Assignment #78 and Counting with a For Loop
Code
/// Name: Lauren Baird
/// Period: 7
/// Program Name: Counting with a For Loop
/// File Name: CountingFor.java
/// Date Finished: 11/18/2015
import java.util.Scanner;
public class CountingFor
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println();
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 );
}
System.out.println();
// n = n+1 makes it so n will print 5 times.
// Without it, it will countinue to print the message, because the computer thinks it is still on number 1.
// The program will not run without int n = 1. You are taking away the variable n and its value.
//
}
}