I cannot find the problem with my code. I even put the negative input into consideration.
package zh.codegym.task.task06.task0606;
import java.io.*;
/*
偶数和奇数
*/
public class Solution {
public static int even;
public static int odd;
public static void main(String[] args) throws IOException {
//在此编写你的代码
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
int n =0;
if (Integer.parseInt(input)>=0){
n = input.length();
}else {
n = input.length()-1;
}
int num = Integer.parseInt(input);
even = 0;
odd = 0;
for (int i = 0; i < n; i++){
if ((num%10)%2 == 0) {
even ++;
}
else{
odd++;
}
num /= 10;
}
System.out.println("偶数:" + even + " 奇数:"+ odd);
}
}