Can someone do this using break and continue statements? import java.util.Scanne
ID: 3925503 • Letter: C
Question
Can someone do this using break and continue statements?
import java.util.Scanner;public class Lab0604 {
public static void main(String[] args) {
int runTime = 0;int totalTime = 0;double avg = 0.0;int numTimes = 0;Scanner inp = new Scanner(System.in);
System.out.print(" Enter running time in seconds or -1 to end: ");runTime = inp.nextInt();while(runTime != -1){
totalTime += runTime;System.out.print(" Enter running time in seconds or -1 to
end: ");
runTime = inp.nextInt();
}
// insert code to report the total time, the number of times entered and theaverage time
} // end of main method } // end of Lab0604 class
Explanation / Answer
package automativ;
import java.util.*;
public class lab0604 {
public static void main(String[] args) {
int runTime = 0;
int totalTime = 0;
double avg = 0.0;
int numTimes = 0;
Scanner inp = new Scanner(System.in);
System.out.print(" Enter running time in seconds or -1 toend: ");
runTime = inp.nextInt();
while(runTime!=-1){
System.out.print(" Enter running time in seconds or -1 toend: ");
runTime = inp.nextInt();
totalTime+=runTime;
numTimes++;
}
avg=totalTime/numTimes;
System.out.println("runtime:"+runTime);
System.out.println("totaltime:"+totalTime);
System.out.println("numtimes:"+numTimes);
System.out.println("avgTimes:"+avg);
}
}
output:
Enter running time in seconds or -1 toend: 2
Enter running time in seconds or -1 toend: 5
Enter running time in seconds or -1 toend: 4
Enter running time in seconds or -1 toend: 6
Enter running time in seconds or -1 toend: 8
Enter running time in seconds or -1 toend: -1
runtime:-1
totaltime:22
numtimes:5
avgTimes:4.0