Java In-Class Exercise 2

Loops

 

 

1. Write a program PrintRange which asks the user for a starting value and an ending value and then writes all the integers between those integers (inclusive)

 

Enter Start:
5
Enter End:
9

5
6
7
8
9

 

2. Write a program WordRepeat that asks a user to enter a word. The program will then repeat the word as many times as the number of characters in the word.

Enter a word:
Hello

Hello
Hello
Hello
Hello
Hello

3. Write a program square which accepts an integer N from the user and then prints a square of side N using asterisks.

 

Enter a number

 

5

 

*****

*****

*****

*****

*****

 

 

MR

[22/11/2006]