For loops #76 (The parrot loop?)

Code

/// Name: Amir Salehi
/// Period: 7
/// Program Name:Counting For
/// File Name:CountingFor.java
/// Date Finished: 2/3/2016

 
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 <= 10 ; n = n+2 )
        {
            System.out.println( n + ". " + message );
        }

    }
}
//What does n = n+1 do? Remove it and see what happens. (Then put it back.): Adds itself the number it has
//What does int n = 1 do? Remove it and see what happens. (Then put it back.) Variable N equals 1.
//
    

Picture(s) of the output

Assignment 7

Back to Homepage