1.你的程序要讀入一系列正整數數據,輸入-1表示輸入結束,-1本身不是輸入的數據。程序輸出讀到的數據中的奇數和偶數的個數。2.源碼如下package count; import java.util.Scanner; public class Count { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int number = 0; int count = 0; int digit = 0; number = in.nextInt(); while ( number != -1) { int a = number % 10; if (a % 2 == 0) { count = count + 1; }else { digit = digit + 1; } number = number / 10; if (number == 0) break; } System.out.println(count ); System.out.println(digit); }}3.為什么直接輸出1和0 不循環呢?
添加回答
舉報
0/150
提交
取消