+ 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.
2 Réponses
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");
0
Thank you