Assignment 78: Counting with a For Loop
Code
/// Name: Ryan McAteer
/// Period: 5
/// Program Name: Counting with a For Loop
/// File Name: Assignment78.java
/// Date Finished: 2/25/16
import java.util.Scanner;
public class Assignment78
{
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 )
//Removing n = n + 1 will make the loop run for infinity ( n will not reach 5)
//n = 1 gives n a value, no value = no program run
{
System.out.println( n + ". " + message );
}
}
}
Picture of the output