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));
int num = Integer.parseInt(reader.readLine());
while (num > 0) {
if (num % 2 == 0) {
even++;
num /= 10;
} else {
odd++;
num /= 10;
}
}
System.out.println("偶数: " + even + " 奇数: " + odd);
}
}
I don't know why other people used if((num%10)%2==0).I tried to used if(num%2==0) this way, it looked didn't go wrong.
已解决
评论 (2)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
Leo Backend Developer 位于 YouthlabTech
20 七月 2020, 09:44
You are right.
0
Let's play video games
21 七月 2020, 01:59
thank you
0