java程序: 输入数量不确定的正数和负数(一次输入一个), 然后打印正数和负数的个数,当输入0时,程序停止
import java.util.Scanner;
public class CountNumber {
/*
* 输入数量不确定的正数和负数(一次输入一个), 然后打印正数和负数的个数,当输入0时,程序停止
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int x = 0;
int y = 0;
int number;
do {
Scanner sc = new Scanner(System.in);
number = sc.nextInt();
if (number > 0) {
x += 1;
} else {
y += 1;
}
} while (number != 0);
System.out.println("正数的个数是:" + x);
System.out.println("负数的个数是:" + (y-1));
}
}