求编一个Java程序:从键盘输入10个数,统计其中的正数、负数和零的个数。

只导入Scanner这个包
2024-11-26 05:23:45
推荐回答(2个)
回答1:

import java.util.Scanner;






public class Count {




    public static void main(String[] args){



        int a = 0;


        int b = 0;


        int c = 0;



        Scanner input = new Scanner(System.in);



        for(int i = 0; i<10; i++){


            int num = input.nextInt();



            if(num == 0)


                a++;


            else if(num > 0)


                b++;


            else


                c++;



        }


        input.close();



        System.out.println("正数个数为"+b+"负数个数为"+c+"0的个数为"+a);


    }




}


回答2:

哥们怎么又是你来?