Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Checking Strings With A For/While Loop?
I have 3 arrays with 11 slots each. I will eventually be placing Strings into each array slot for the final product of this project. As of right now to locate and identify particular slots i have assigned each of the 33 slots a number, 1-33. I would like to be able to run a for loop to identify the slot by the number but the problem is that they are strings and need to stay that way. Any Ideas?
2 Answers
- MarkF120Lv 48 years agoFavorite Answer
String[][] a = new String[3][11];
int slot = 0;
for(int i = 0; i < a.length(); i++) {
for(int j = 0; j < a[i].length(); j++) {
// code...
slot++;
}
}
- Puter_NotgeekLv 58 years ago
You can make the String arrays, the 'slots' are accessed by a number.
Like having 33 garages, they hold cars, but each garage is numbered.
So make either 3 String arrays, or like the person above, a 3d array, 3 down, 11 across.
Inside they hold String is all. An array can hold whatever type you say.
Accessing them is through the number and almost always a for loop.
It should go from 0-32, which is 33, remember that.