I'm having trouble solving the following exercise:
- Create a class with a main method;
- Create a 10-position int array and popule using for
- Print all the values in the array and, for even values, display the value followed by the word "even" (use the% operator to par)
Firstly I did this, but it is giving compilation error:
public class MeuArray {
public static void main (String[] args) {
int[] MeuArray = new int[10];
for (int i = 0; i < 10; i++){
if (MeuArray[i] % 2 == 0) {
System.out.prinln("O vetor é par:", MeuArray[i]);
} else {
System.out.println("O vetor é impar:" MeuArray[i]);
}
}
}
}
I changed to this code and the outputs are showing the result 0:
public class MeuArray {
public static void main (String[] args) {
int[] MeuArray = new int[10];
for (int i = 0; i < 10; i++){
if (MeuArray[i] % 2 == 0) {
System.out.println(MeuArray[i]);
} else {
System.out.println(MeuArray[i]);
}
}
}
}