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; } } } }