Hallo,
ich bin momentan an einer stolperstelle agelangt.
Ich möchte eine sogenannte "For-each-Schleife" anwenden und kreige das nicht hin .
Vielleicht kann mir jemand helfen ?
Wäre für jeden Tipp dankbar
package de.codegym.task.task06.task0606;
import java.io.*;
public class Solution {
public static int gerade;
public static int ungerade;
public static int a =gerade;
public static int b =ungerade;
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String num = reader.readLine();
int zahl [] ={ Integer.parseInt(num )};
for (int element : zahl) {
if (element % 2 == 0) {
a++;
} else {
b++;
}
}
System.out.println("Gerade:" + a);
System.out.println("Ungerade:" + b);
}
}