Assignemnt #63: Counting with While Loops
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: Counting and While Loops
/// File Name: CountingWhile.java
/// Date Finished: 12/4/2015
import java.util.Scanner;
public class CountingWhile
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int n, Number;
n = 0;
System.out.println( "Type in a message, and I'll display it." );
System.out.print( "Message: " );
String message = keyboard.nextLine();
System.out.println( "How many times would you like it displayed?" );
Number = keyboard.nextInt();
while ( n < Number )
{
System.out.println( (n*10 + 10) + "." + message );
n++;
}
}
}
/// the n++ line prevents the computer from infinitely repeating the same first line over and over, oit allows it to progress.
Picture of the output