English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a loop that creates 5 versions of a variable. I would like the variable to be named something like
string0
string1
string2
...
I just want to tack on the value of the incrementing integer to the name of the variables.
How would I do this? Thanks

2007-05-15 08:15:59 · 4 answers · asked by snoboarder2k6 3 in Computers & Internet Programming & Design

4 answers

Are you sure you want to do that rather than work with an array?

// Initialize a String array of 5
String[] myString = new String[5];

// Set the String array programmatically with increasing values.
for (int i = 0; i < 5; i++) {
myString[i] = new String("This is string " + i + ".");
}

// Print out the content of an unknown length array (known in this case but to allow for runtime check of length of the array)
for (int i = 0; i < myString.length(); i++) {
System.out.println("myString[" + i + "] = " + myString[i]);
}

2007-05-15 08:22:30 · answer #1 · answered by Jim Maryland 7 · 0 1

after defining variables you create a jointly as loop jointly as (totalDonation != DONATIONTARGET); get call etc and increment type of donations } // ends jointly as loop then print consequences } // ends classification

2016-12-17 13:37:42 · answer #2 · answered by Anonymous · 0 0

hey u cant do dat..better use array..
n if u want only de varialbe name u can do it by making the integer string by Integer.toString() fn and den concatinating to variable name....

jj

2007-05-15 08:23:10 · answer #3 · answered by JJ 4 · 0 1

Use an array.

See this link: http://www.w3schools.com/js/tryit.asp?filename=tryjs_array

The Data Analyst - http://www.squido.com/thedataanalyst

2007-05-15 08:19:17 · answer #4 · answered by a_non_a_miss_2000 3 · 0 1

fedest.com, questions and answers