Assignment 78, Counting With a For Loop
Code
///Name: Stella Koliavas
///Period: 5
///File Name: CoutingFor.java
///Date Finshed: 2/16/16
import java.util.Scanner;
public class CountingFor
{
public static void main( String[] args )
{
Scanner siri = new Scanner(System.in);
System.out.println( "Type in a message, and I'll display it five times." );
System.out.print( "Message: " );
String message = siri.nextLine();
for ( int n = 1 ; n <= 5 ; n = n+1 )///n = n+1 makes it add one each time, int n = 1
sets n as an integer and start counting at 1
{
System.out.println( n + ". " + message );
}
}
}
Picture of the output