Write three statements to print the first three elements of array runTimes. Follow each statement with a newline. Ex: If runTime = {800, 775, 790, 805, 808}, print: 800 775 790 Also note: If the submitted code tries to access an invalid array element, such as runTimes[9] for a 5-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message. import java.util.Scanner; public class PrintRunTimes {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);final int NUM_ELEMENTS = 5;int [] runTimes = new int[NUM_ELEMENTS];int i; for (i = 0; i < runTimes.length; ++i) {runTimes[i] = scnr.nextInt();} /* Your solution goes here */ }}
Write three statements to print the first three elements of array runTimes. Follow each statement with a newline. Ex: If runTime = {800, 775, 790, 805, 808}, print:
800
775
790
Also note: If the submitted code tries to access an invalid array element, such as runTimes[9] for a 5-element array, the test may generate strange results. Or the test may crash and report "
import java.util.Scanner;
public class PrintRunTimes {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
final int NUM_ELEMENTS = 5;
int [] runTimes = new int[NUM_ELEMENTS];
int i;
for (i = 0; i < runTimes.length; ++i) {
runTimes[i] = scnr.nextInt();
}
/* Your solution goes here */
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images