Prog78: Counting with a For Loop
///Name: Ilana Levy
///Period: 5
///Program Name: Counting with a For Loop
///File Name: forCounting.java
///Date Finished: 9/24/2015
import java.util.Scanner;
public class forCounting
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println( "Type in a message, and I'll display it five times." );
System.out.print( "Message: " );
String message = keyboard.nextLine();
for ( int n = 2 ; n <= 10 ; n = n+2 )
{
System.out.println( n + ". " + message );
}
}
}
///1. n = n + 1 sets the counter and makes it count the number of times the message has been displayed, without it, the message repeats forever, always recorded as being printed the first time.
///2. It reports a number of new errors because n is not initialized.