package com.example.practice;
import java.util.Scanner;
//统计从键盘输入的正负数的个数,输入0时程序自动结束
public class Test6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int positiveNum = 0;//统计正数的个数
int negativeNum = 0;//统计负数的个数
while (true) {
System.out.println("请输入:");
int i = input.nextInt();
if (i > 0) {
positiveNum++;
} else if (i < 0) {
negativeNum++;
} else {
break;
}
}
System.out.println("正数的个数为:" + positiveNum + "\t" + "负数的个数为:" + negativeNum);
}
}
标签:negativeNum,int,个数,System,键盘输入,positiveNum,正负数
From: https://www.cnblogs.com/faith007/p/17214710.html