Assignment #78 and Counting with for Loops
Code
//Name: Mark Katz
///Period: 6
///Program Name: Counting With for loops
///File Name: counting.java
///Date Finished: 11/4/15
import java.util.Scanner;
public class couting
{
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 <= 20; n = n + 2 )
{
System.out.println( n + ". " + message );
}
}
}
// if you remove the n= n+1 the program will go on forever. It adds 1 to n, and when it hits five, its stops.
// if you remvoe the in n=1 then there is nothing to initialize the n
Picture of the output