Assignemnt #63, Counting with While Loop
Code
/// Name: Alex Pinder
/// Period: 5
/// Program Name: Counting with While Loop
/// File Name: CountingWhile.java
/// Date Complete: 1/11/16
import java.util.Scanner;
public class CountingWhile
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int n, t;
n = 0;
System.out.println( "Type in a message, and I'll display it." );
System.out.print( "Message: " );
String message = keyboard.nextLine();
System.out.print( "How many times? " );
t = keyboard.nextInt();
while ( n < t )
{
System.out.println( ((n+1)*10) + ". " + message );
n++;//Removing this makes the program run forever.
}
}
}
Picture of the output