JAVA
Prompt the user for 10 numbers using a while loop. Create an int variable number. You have three additional int variables pos, neg, and zero. Your goal is to determine the number of positive, negative, and zeroes in the list of the ten numbers read in.
Source Code in text format (See below images of code for indentation):
import java.util.*;
/*class definition*/
public class Main
{
/*main method*/
public static void main(String[] args)
{
/*Scanner object to read input from the user*/
Scanner read=new Scanner(System.in);
/*variables*/
int number,pos=0,neg=0,zero=0,i=0;
/*read 10 numbers from user*/
System.out.println("Enter 10 numbers:");
while(i<10)
{
/*read a number from user*/
number=read.nextInt();
/*check for negative*/
if(number<0)
neg++;
/*check for positive*/
else if(number>0)
pos++;
/*zeroes*/
else
zero++;
i++;
}
/*print all counts*/
System.out.println("The number of positive numbers: "+pos);
System.out.println("The number of negative numbers: "+neg);
System.out.println("The number of zeros: "+zero);
}
}
Source Code:
Output:
Get Answers For Free
Most questions answered within 1 hours.