Programming Exercises

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.

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.