Input positive and auxiliary numbers from the keyboard, count the number of positive and negative numbers respectively, and calculate the sum of all numbers

The code is as follows:

/*Input positive and auxiliary numbers from the keyboard, count the number of positive and negative numbers respectively, and calculate the sum of all numbers. Enter 0 to end * / import Java util. Scanner; Class demo15 {public static void main (string [] args) {scanner SC = new scanner (system. In); int num = 1, t = 0, f = 0, sum = 0; while (Num! = 0) {system.out.println ("please enter an integer:"); num = sc.nextint(); sum + = num; if (Num > 0) t + +; else if (Num < 0) F + +;} System. out. Println ("positive numbers have" + T + "numbers" + ", negative numbers have" + F + "numbers" + ", and the sum of all numbers is:" + sum);}}

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>