created 08/04/99


Chapter 15 Programming Exercises

Exercise 1

Write a program that asks the user for a starting value and an ending value and then writes all the integers (inclusive) between those two values.

Enter Start:
5
Enter End:
9

5
6
7
8
9
Click here to go back to the main menu.

Exercise 2

Write a program that asks the user to enter a word. The program will then repeat word for as many times as it has characters:

Enter a word:
Hello

Hello
Hello
Hello
Hello
Hello

To do this you will need to use the length() method that counts the number of characters in a string:

String inputString;
int times;

 . . . .

times = inputString.length()
Click here to go back to the main menu.

Exercise 3

Write a program that asks the user to enter two words. The program then prints out both words on one line. The words will be separated by enought dots so that the total line length is 30:

Enter first word:
turtle
Enter second word
153

turtle....................153

This could be used as part of an index for a book. To print out the dots, use System.out.print(".") inside a loop body.

Click here to go back to the main menu.

End of exercises.