Assignemnt #63 and Counting with a While Loop
Code
import java.util.Scanner;
public class CountingWhile
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println( "Type in a message, and I'll display it several times." );
System.out.print( "Message: " );
String message = keyboard.nextLine();
System.out.println("How Many Times? ");
int x = keyboard.nextInt();
int n = 0;
while ( n != x )
{
System.out.println( (n+1)*10 + ". " + message );
n++;
}
// n++ adds 1 after the loop is executed. If you remove n++ it will infintely repeat because n stays at a value of zero.
// change the while to (n < 10)
// change line 18 to (n+10)*10
}
}
Picture of the output