Good day,
I'm new to Java and have been practicing with Nested Loop iterations. I was wondering if there is any simpler way on how to do this? Especially on the part where I had to put this [j+1].
String[][] entry = {{"010", "John", "Male", "21"},
{"011", "Mary", "Female", "25"},
{"012", "Joseph", "Male", "24"},
{"013", "Peter", "Male", "22"}};
for ( int i = 0; i < entry.length; i++) {
for ( int j = 0; j < entry[i].length;) {
System.out.print("ID: " + entry[i][j] + "\n");
System.out.print("Name: " + entry[i][j+1] + "\n");
System.out.print("Gender: " + entry[i][j+2] + "\n");
System.out.print("Age: " + entry[i][j+3] + "\n");
System.out.println("");
break;
}
}
Expected output is like this:
ID: 010
Name: John
Gender: Male
Age: 21
ID: 011
Name: Mary
Gender: Female
Age: 25
ID: 012
Name: Joseph
Gender: Male
Age: 24
ID: 013
Name: Peter
Gender: Male
Age: 22
Your help is highly appreciated!