You are on page 1of 2

Object Oriented Programming Essentials

Tutorial 5 – Repetition Logic

 Create a folder called Tutorial 5 to save all files.


 Write Java programs for each of the questions below.

1. Write a program called JavaLoops that uses the specified loops to print the following:

a. all the numbers from 1 to 20. [for loop]

b. all the numbers from 99 down to 85 [for loop]

c. all the even numbers from 40 to 75. [for loop]

d. all the numbers from 20 to 40 . [while loop]

e. all odd numbers from 37 down to 20. [while loop]

f. the sum of all the numbers from 80 to 100. [for loop]

OUTPUT NOTE – for each of the questions above


 print a message indicating what is being printed and
 print the range of numbers on one line.
For example:
All the numbers from 30 to 40:
30 31 32 33 34 35 36 37 38 39 40
2. Write a program called QuizMarks that uses a for loop to allow a user to enter 7 quiz

marks (out of 100) and print the following:

a. The highest and lowest mark made.

b. How many students passed and how many failed.

3. Write a program called ItemsBought that allows a user to enter the prices of items

bought in a store and print the average cost of the items. The user enters a negative

value to indicate that there are no more prices to be entered.

You might also like