Hello,
the code is actually displaying what the task wanted, yet somehow it is verified as it was wrong. Can anyone spot the mistake?
package com.codegym.task.task06.task0606;
import java.io.*;
import java.util.Scanner;
/*
Even and odd digits
*/
public class Solution {
public static int even;
public static int odd;
public static void main(String[] args) throws IOException {
//write your code here
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int a = 0;
int b = 0;
int mul = 1;
int digits = 0;
while (true){
if (x == 0 || x >= mul){
digits += 1;
}
else{
break;
}
mul *= 10;
}
for (int i = 0 ; i < digits; i++){
if (x % 2 == 0){
a += 1;
}
else if (x % 2 == 1){
b += 1;
}
x = x / 10;
}
System.out.print("Even: " + a + " Odd: " + b);
}
}