You are on page 1of 3

Java Looping Exercises

1. Make a program that accepts 10 integers and display the average of the ten inputted integers.
Example:
Enter number 1: 67
Enter number 2: 56
Enter number 3: 50
Enter number 4: 49
Enter number 5: 88
Enter number 6: 13
Enter number 7: 29
Enter number 8: 22
Enter number 9: 76
Enter number10: 52
The average of the ten given numbers is 50.2

2. Make a program that accepts 10 inputs number between 1 to 100, and display the sum of the inputted
numbers and also the highest number.
Example:
Enter number 1: 9
Enter number 2: 26
Enter number 3: 90
Enter number 4: 34
Enter number 5: 100
Enter number 6: 13
Enter number 7: 29
Enter number 8: 8
Enter number 9: 5
Enter number10: 50
Total sum of the inputted numbers is: 364
Highest Number: 100

3. Make a program that accepts a number until the inputted number is 0. Display the sum and average of
the inputted number.
Example:
Enter a number: 12
Enter a number: 21
Enter a number: 32
Enter a number: 50
Enter a number: 0
Sum of the inputted number: 115
Average of the inputted number: 28.75

4. Make a program that accepts 10 inputs number and display all inputted even and odd numbers
separately.
Example:
Enter number[1]: 5
Enter number[2]: 6
Enter number[3]: 12
Enter number[4]: 23
Enter number[5]: 9
Enter number[6]: 11
Enter number[7]: 100
Enter number[8]: 13
Enter number[9]: 29
Enter number[10]: 40

Even numbers: 6, 12, 100, 40,


Odd Numbers: 5, 23, 9, 11, 13, 29,

5. Make a program that reverses the inputted number.


Example:
Enter a number: 8321
Output: 1238

6. Make a program that accepts an integer number and displays its binary equivalent.
Binary is a number system whose digit is composed 1’s and 0’s only. To convert the integer number to
binary, you will divide the number by 2 and get the remainder. The quotient will be the new number.
Repeat the process until the number is zero.
Conversion Process:
Number = 25
25 / 2 = 12 rem=1
12 / 2 = 6 rem=0
6 /2=3 rem=0
3 /2=1 rem=1
1 /2=0 rem=1
To get the binary equivalent, read the remainders from bottom to top. So the binary equivalent
will be equal to 11001.

Example:
Enter integer number: 25
Binary Equivalent: 11001

7. Create a program that display the Fibonacci series with the inputted iteration. Iteration is the count of the
number on series.
Fibonacci Series is a number series that starts from two numbers both equal to 1 and the following
numbers is the sum of two previous number.
Fibonacci: 1 1 2 3 5 8 13 21 34 55 89 and so on..

Example:
Enter iteration: 10
Fibonacci Series: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
8. Make a Guessing Game program that asked a user to enter a number and compare it to the computer
generated integer number. The computer generated number should be from 1 to 100 only. Also, your
program will tell the user if his/her input is too high or too low from the generated number and display
congratulations if it will match.
Example:
Enter a number:

9. Make a program that inputs a number and a character and display it from 1 up to the inputted number.
Output:
Enter a number: 5
Enter a Character: *
*
**
***
****
*****

You might also like