Assignment #78
Code
///Name: Cody Swain
///Period: 6
///Project Name: CountingFor
///File Name: CountingFor.java
///Date: 1/12/16
import java.util.Scanner;
public class CountingFor
{
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 <= 11 ; n = n+2 )
{
System.out.println( n + ". " + message );
}
}
}
/*
1. (n = n + 1) makes it so that on the next loop n will be one digit higher. That way instead of repeating indefinitely, the loop will repeat only the number of times set.
2. It initially initializes n as 1. Only when the loop is starting in the very beginning though.
*/
Picture of the output