Question: Integer numSuccesses is initialized with 0 . Input consists of integers that are raw data of an experiment. Write a while loop that iterates until

Integer numSuccesses is initialized with 0. Input consists of integers that are raw data of an experiment. Write a while loop that iterates until numSuccesses is equal to 3. In each iteration of the loop:
Read integer currDepth from input.
If currDepth is between 13 and 43, both inclusive, then increment numSuccesses and output currDepth followed by a newline.
Click here for example
Note: Assume that input has at least three integers.
import java.util.Scanner;
public class SimpleWhileLoop {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
int currDepth;
int numSuccesses;
numSuccesses =0;
while (numSuccesses <3){
currDepth = scnr.nextInt();
if (currDepth >=13 && currDepth <=43){
numSuccesses++;
System.out.println(currDepth);
}
}

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 Databases Questions!