Question: Use scnr . nextInt ( ) to read remaining integers from input into dataValue until 1 0 0 0 is read. For each integer read

Use scnr.nextInt() to read remaining integers from input into dataValue until 1000 is read. For each integer read before 1000:
If the integer is non-negative, output the integer followed by " spotted" and increment numCounts.
Otherwise, output the negative integer.
End each output with a newline.
Ex: If the input is -20102051000, then the output is:
-20
10 spotted
20}\mathrm{ spotted
5 spotted
Non-negative integers occur 3 time(s)
Note: The sentinel value is 1000.
import java.util.Scanner;
public class NumCounts {
public static void main(String[] args){
Scanner scnr = new Scanner(
System.in);
int dataValue;
int numCounts;
numCounts =0;
while (true){
dataValue = scnr.nextInt();
}
System.out.println("Non-negative integers occur "+ numCounts +" time(s)");
}
}
Use scnr . nextInt ( ) to read remaining integers

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!