131k views
3 votes
In Java, write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print:

7 9 11 10
10 11 9 7

In Java, write a for loop to print all elements in courseGrades, following each element-example-1
User Harshana
by
4.4k points

1 Answer

5 votes

Answer:

public class CourseGradePrinter {

public static void main(String[] args) {

int[] courseGrades = {7, 9, 11, 10};

// Print elements forwards

for (int i = 0; i < courseGrades.length; i++) {

System.out.print(courseGrades[i] + " ");

}

System.out.println();

// Print elements backwards

for (int i = courseGrades.length - 1; i >= 0; i--) {

System.out.print(courseGrades[i] + " ");

}

System.out.println();

}

}

User Alan Pierce
by
4.6k points