public class Solution {
public static int even;
public static int odd;
public static void main(String[] args) throws IOException {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(reader.readLine());
while (a > 0) {
int remainder = a % 10;
if (a % 2 == 0)
even++;
else
odd++;
a = a / 10;
}
System.out.println("Even: " + even);
System.out.println("Odd: " + odd);
}
}

# Somebody can explain to me how this code is working?

Resolved

number % 10is the last digit of the number. ifreminder % 2 = 0then the number is even,elseisodd. Thenumber gets divided by 10so you can get rid of the last digit. Repeat operation. This is how I prefer to do it. if(a % 2 == 0) is fine too. You just don't use the reminder in the operation.