473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I make a pig latin program that DOESNT glitch out on a single charecter?

16
I am so very close to making this program happen, however I am running into an error with single character words.


When My program runs, if I put a single letter word in like

A or I

then it glitches out on me! something about it going out of bounds...what should I do? I'm trying to declare an if statement that will fix the problem "if length >2, then print as something"

but I CANT get it to work...please help

import java.util.Scanner;
Jan 28 '11 #1

✓ answered by Rabbit

Your x, y, z, q, m, and qu variables are still in the wrong place. They need to be inside the else part of the if.

You don't give a string a bound, a string is automatically bound by it's length.

14 2197
Rabbit
12,516 Expert Mod 8TB
Where's the if length part of the code you mentioned?
Jan 28 '11 #2
berky
16
this is the error message
Jan 28 '11 #3
berky
16
the if statement below the Q
Jan 28 '11 #4
Rabbit
12,516 Expert Mod 8TB
Well, what you really want is .length()>1, not 2. And the length check needs to go before everything else and if the length is 1, then you need to skip the rest of the pig latin transformation.
Jan 28 '11 #5
berky
16
I put it to the front of the for loop and set it to 1. I still get the error, and now my vowel statement doubles up :/
Jan 28 '11 #6
Rabbit
12,516 Expert Mod 8TB
You put the if outside the for loop? It needs to be inside the for loop but before everything else.
Jan 28 '11 #7
berky
16
oh no, I put it in the for loop before everything. Set it to 1 and I continue to get this strange error :/. Whats worse it I dont comment it out then it ends up screwing up my other if statements and making them print additional things.
Jan 28 '11 #8
Rabbit
12,516 Expert Mod 8TB
I think you misunderstood my meaning. What you want to do is something akin to the following. Note that what follows is only pseudocode.
Expand|Select|Wrap|Line Numbers
  1. For Each word In wordList
  2.   If word.length == 1 Then
  3.     pigLatin = pigLatin + word
  4.   Else
  5.     // Rest of code
  6.   End If
  7. Next word
Jan 28 '11 #9
berky
16
I...THINK I did what you said. Which did fix the reapeat code error, however I am still getting the "I A, single character" error.It says Im going out of bound, which is strange considering I dont think I gave it a bound.
Jan 28 '11 #10
Rabbit
12,516 Expert Mod 8TB
Your x, y, z, q, m, and qu variables are still in the wrong place. They need to be inside the else part of the if.

You don't give a string a bound, a string is automatically bound by it's length.
Jan 28 '11 #11
berky
16
oh my goodness...IT WORKS! THANK YOU SO MUCH FOR YOUR HELP!!!
Jan 28 '11 #12
berky
16
I wonder though, the variables where still in the for loop, why did that mess things up?
Jan 28 '11 #13
Rabbit
12,516 Expert Mod 8TB
The for loop has nothing to do with the error. It's because it was outside the if section that was testing for string length.

If your string is one character long, and you're trying to get the second character of a one character string, you're going to go out of bounds.

Expand|Select|Wrap|Line Numbers
  1. Index [0] [1] [2]
  2.        A
  3.        B   A   R
For the first string, you're trying to get the character at index 1. There is no character at index 1. You are out of bounds.
Jan 28 '11 #14
berky
16
interesting, I though they where global and worked throughout the function. Would I get the same effect if I put them out of the for loop and in the beginning of the program?
Jan 28 '11 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: nibha kothari | last post by:
Hi, I am trying to invoke an external email management program from my ASP.NET web application. For testing purposes I created a very simple webform that has a single button. The code behind...
3
by: Martin Ink | last post by:
I have a program linked to an .exe and this program is started from an other program. I would like to control the execution of the program so that the program only runs 'single threaded'. I don't...
2
by: Rick | last post by:
Hi, Would it be right to say that C is a single-tasking environment? pThreads and other variants aren't really "C"? Thanks Rick
10
by: feel52 | last post by:
Below you'll find the code i'm working on. It's in a button click routine and hangs after 3 or 4 sometimes 5 loops done, probably in sock.receive(....). Some code was found here( on google i mean)...
3
by: Arun Nair | last post by:
''' Can anyone help me with this program it just takes probability of the first team and runs the program doesnt takes the probability of the second team even though specified''' from random...
0
by: joestevens232 | last post by:
I need some serious help...I got the first part of the program done the accountant part but i can't figure out how to do the checker..i have been trying for hours and nothings workin any help or...
2
by: Graham Menhennitt | last post by:
I have a large Python 2.5 program that I want my users to be able to "extend" using a Python script. However, I want their script to run in a sandbox within the overall program so that they only...
14
by: johnmac | last post by:
i got my pig latin program which looks like this Dim strInput, str1stCharacter, strOutput, stranswer As String, intStringLength As Integer strInput = txtenglish.Text ...
10
maxx233
by: maxx233 | last post by:
Hi, I'm new to OO and GUI programming and would like to know: what's a good standard way of creating an application that loads different function-content in a standard space on a single form? In...
5
by: deanwarren | last post by:
Hi there I am having problems getting a successfully compiled/linked g++ program to run under Ubuntu linux. A simple hello world program : #include <iostream> int main (int argc, ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.