/* 9/25/2019 */ import java.util.Scanner; /** Problem: read in and print out a number of test grades * this program illustrates the for loop. */ public class ForLoop { public static void main(String[] args) { for (int i=0; i<7; i++) { System.out.println("i=" + i); } // i has block scope and is not available outside of loop // System.out.println("outside of loop i is: " + i ); int numGrades ; Scanner scanner = new Scanner(System.in); // use a for loop to read in numGrades grade // What if pgmer does not know the number of grades? // attempt 1: ask the user how many grades there are System.out.println("How many grades are there? "); numGrades = scanner.nextInt(); for (int i=0; i < numGrades; i++) { System.out.println("Enter a grade: "); double grade = scanner.nextDouble(); System.out.println("Grade " + i + " " + grade); } scanner.close(); } }