Assignment #63 and Counting with a While Loop

Code

    /// Name: Ali Kurland
    /// Period: 6
    /// Program Name: Counting with a While Loop
    /// File Name: CountingWhile.java
    /// Date Finished: 10/9/2015
    
    /// 1. n++ adds 1 to the int n, so it makes the program repeat only until n is greater than 5. Without n++, n is always equal to 1, so the while loop will run forever.
    
    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.print( "How many times? " );
            int q = keyboard.nextInt();
            int n = 0;
            while ( n < q )
            {
                System.out.println( ((n+1) * 10) + ". " + message );
                n++;
            }
    
      }
    }
    

Picture of the output

#1

Assignment 63

#2

Assignment 63

#3

Assignment 63

#4

Assignment 63