1.你的程序要讀入一系列正整數(shù)數(shù)據(jù),輸入-1表示輸入結(jié)束,-1本身不是輸入的數(shù)據(jù)。程序輸出讀到的數(shù)據(jù)中的奇數(shù)和偶數(shù)的個(gè)數(shù)。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 不循環(huán)呢?
添加回答
舉報(bào)
0/150
提交
取消