About Question enthuware.ocpjp.i.v11.2.1454 :
Posted: Fri Nov 20, 2020 8:28 am
I think, it is also possible to use an enhanced for loop for all the tasks (also task 2 and 3). Of course, that doesn't make sense.
An example solutions is presented below.
An example solutions is presented below.
Code: Select all
public static void main(String args[]) {
String[] array = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"};
for (String x : array) {
System.out.println(x);
}
int i = array.length - 1;
for (String x : array){
System.out.println(array[i]);
--i;
}
i = 0;
for (String x : array){
if(i%2 == 0) {
System.out.println(array[i]);
}
++i;
}
}