Assignment #63 Counting with a While Loop
Code
/// Name: John Huh
/// Period: 6
/// Program Name: Counting with a While Loop
/// File Name: CountingWhile.java
/// Date Finished: 12/10/2015
import java.util.Scanner;
public class CountingWhile
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int n, times;
n = 1;
System.out.println( "Type in a message, and I'll display it ten times." );
System.out.print( "Message: " );
String message = keyboard.nextLine();
System.out.print( "How many times? " );
times = keyboard.nextInt();
while ( n <= times )
{
System.out.println( (n*10) + ". " + message );
n++;
// Removing n++ causes the program to repeat what I typed without stopping
}
}
}
Picture of the output