+ 2

Write a program in java to input any 50 number (including positive and negative) and count the positive number and negative ...

Write a program in java to input any 50 number (including positive and negative) and count the positive number and negative and the sum of positive no. and the sum of negative no.

23rd Feb 2018, 12:33 PM
agarsom
2 odpowiedzi
0
Scanner in = new Scanner(System.in); System.out.print("type in 50 numbers"); double sum = 0; int countP = 0; int countN = 0; for(int i = 0;i<50;i++){ double num = in.nextDouble(); if(num >= 0){ countP++; sum += num; }else { countN++; } } System.out.println("#of positive numbers is " + countP + " and their total is " + sum); System.out.println("there are " + countN + " negative numbers");
23rd Feb 2018, 12:58 PM
Basel Abuhadrous
Basel Abuhadrous - avatar
0
Thank you
23rd Nov 2020, 3:46 AM
T.Sohan
T.Sohan - avatar