Assignemnt #78, Counting With a For Loop
Code
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 = 1 ; n <= 10 ; n = n+1 ) // n = 1 is the variable initilizer while n = n+1 is what adds more to the value of n.
{
System.out.println( (n*2) + ". " + message );
}
}
}
Picture of the output