My example was terrible...after putting a bit more thought into it, this example would be better: int someInt = 100; for (int a = 0; a < someInt; a++) { String testString + someInt = "YUP"; } So you would get 100 Strings such as testString1, testString2...testString100 Hope this makes it a bit more clear! Thanks! Jason
Hello! In order to make my programs run with less code I would like to know if I can name objects with a String..I did it when I was into Visual Basic...something like this: String testName = "testName" int testName = 14 Is this possible at all??? Thanks, Jason
Hello, I have an array that contains Points that are found on an X-Y axes. I am trying to sort these Points by their closeness to one another. In theory, I need to take the first point in my array, add it to the new array. Then take the second point in my array and insert it into the second place in the new array..heres where the fun starts...I then take the third point of my first array and check to see how far it is from the each of the 2 points in my new array, then it gets inserted into the new array directly after the point to which it is closest. Then we go to the fourth point and compare its distance from each of the 3 points in my new sorted array and insert it after the point that it is closest and so on until I run out of points...I am completely lost on this one...I am not looking for someone to feed me a ton of code that I can just plug in and go, I would like for someone to just point me in the right direction so I can at least get started... Thanks for your time!! Jason
Here is my code...I was hoping I could get another pair of eyes to scan it and see what I might be doing wrong...All of my organisms die after the first cycle!
Can someone help me to see why the variable result is valued at 88 and not 10? import javax.swing.*; import java.text.*; import java.util.StringTokenizer; public class romanNumeral { public static void main(String[] args)
Hi, I want to take a string such as "Hello" and convert that to a string that looks like this: "h + e + l + l + o" . This is the loop that I am using to try to accomplish this feat: import javax.swing.*; import java.text.*; import java.util.StringTokenizer; public class romanNumeral //Naming the class and declaring it to be public {//begin class public static void main(String[] args)
{//begin method String input = "hello";
StringTokenizer tokenizer = new StringTokenizer (input);
int stringLength = input.length();
String word = " ";
String digit;
while (tokenizer.hasMoreTokens())
{//begin while
digit = tokenizer.nextToken();
if (stringLength == 1)
{//begin if
word = word + " " + digit;
}//end if
else
{//begin else
word = word + digit + " + " + stringLength;
}//end else
stringLength = stringLength - 1;
}//end while
JOptionPane.showMessageDialog(null,
"Your converted string is " + word,
"The Results",
JOptionPane.INFORMATION_MESSAGE);
}//end method
}//end class This code returns "hello +". I know that this is because the delimiter is not set right but I am not sure how to tell it to set each character as its own token as opposed to each word. Please help! Jason
I am not sure what you mean..I just pasted the code in from JGrasp and tried to make it more readable for you... I also figured out that I needed to declare my variable outside of the main method to use them in more than that one method, it seems to work ok now... thanks for the help Jason
Hi, I am not sure what is wrong with the following code, and was hoping that someone would shed some light on why I am getting the following errors when I try to compile. newGame.java:55: cannot resolve symbol symbol : variable number location: class newGame else if (test > number) ^ newGame.java:63: cannot resolve symbol symbol : variable number location: class newGame else if (test < number) ^ 2 errors
----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. PLEASE HELP!! (here is the code) import javax.swing.*; import java.text.*; import java.util.Random; public class newGame { public static void main(String[] args) { Random generator = new Random(); int number = generator.nextInt(1000); String userInput = JOptionPane.showInputDialog("Give me a number between 0 and 1000"); int stringLength = userInput.length(); int guess = Integer.parseInt(userInput); int checkedGuess = errorCheck(guess); } public static int errorCheck(int test) { if (test > 1000) { return 0; } else if (test > number) { return 1; } else if (test < number) { return 2; } else return 3; } }