Program Flow  «Prev  Next»

While Loops - Exercise

Using Java while loop

Objective: Practice using the while loop.

Exercise Grading

The full credit for this exercise is 10 points. To receive full credit, you willl need to successfully create the source code for the application. You will submit your source code.

Exercise instructions

Develop a command-line application named PrintMessage that uses a while loop to print a message a number of times. The message and number of repetitions should be provided as command-line arguments. In this application you will need to convert a command-line argument from a String to an int. The static method parseInt() in class Integer provides this functionality. Here is an example of parseInt() in action:

String s = new String("123");
int    n = Integer.parseInt(s);

What to submit to the course

In the text box below, cut and paste the source code for the PrintMessage application. Click, Submit to submit the code .