I am new in programming. Need to have your advise to shorten improve my code below.
public class Exercise4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[][] info = {{"010","John","Male","21"},
{"011","Mary","Female","25"},
{"012","Joseph","Male","24"},
{"013","Peter","Male","22"}};
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
if(j == 0) {
System.out.print("ID: ");
} else if(j == 1) {
System.out.print("Name: ");
} else if(j == 2) {
System.out.print("Gender: ");
} else if(j == 3) {
System.out.print("Age: ");
}
System.out.println(info[i][j]);
}
System.out.println();
}
}
}
This will display the following output. Is there any way to improve/shorten my code? I think there's a way to shorten it but I just couldn't figure it out.
Output:
