【Kay】Java判断正数和负数个数
作者:互联网
Java输入一串数字,输入0则返回正数和负数个数
import java.util.Scanner;
public class nummm {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int posi = 0;
int nega = 0;
while(true){ //写true的话循环会一直进行,写1=1也行,想结束用break。while(true) = for(;;)
int num = input.nextInt();
if (num > 0){
posi+=1;
}else if(num<0){
nega+=1;
}else{
System.out.println("正数个数"+posi);
System.out.println("负数个数"+nega);
break;
}
}
}
}
标签:Java,Scanner,int,num,Kay,正数,true,public 来源: https://blog.csdn.net/m0_54115636/article/details/122859376