You are on page 1of 5

1. Write a program that print Hello world 100 times.

2. Write a program that print from number 1 – 100.


3. Write a program in Java to display n terms of natural numbers and their sum.
4. Write a program in Java to input 5 numbers from keyboard and find their sum and average.
5. Write a program in Java to display the cube of the number up to given an integer.
Test Data
Input number of terms : 4
Expected Output :
Number is : 1 and cube of 1 is : 1
Number is : 2 and cube of 2 is : 8
Number is : 3 and cube of 3 is : 27
Number is : 4 and cube of 4 is : 64
6. Write a program in Java to display the multiplication table of a given integer up to 10.
Test Data
Input the number (Table to be calculated) : Input number of terms : 5
Expected Output :
5X0=0
5X1=5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25 …
7. Write a program in Java to display the n terms of odd natural number and their sum.
Test Data
Input number of terms is: 5
Expected Output :
The odd numbers are :
1
3
5
7
9
The Sum of odd Natural Number upto 5 terms is: 25
8. Write a program in Java to display the pattern like right angle triangle with a number. Test Data
Input number of rows : 10
Expected Output :
1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910
9. Write a program in Java to make such a pattern like right angle triangle with a number which will
repeat a number in a row. The pattern is as follows :
1
22
333
4444
10. Write a program in Java to make such a pattern like right angle triangle with number increased
by 1. The pattern like :
1
23
456
7 8 9 10
11. Write a program in Java to make such a pattern like a pyramid with a number which will repeat
the number in the same row.
1
22
333
4444
12. Write a program in Java to print the Floyd's Triangle.
Test Data
Input number of rows : 5
Expected Output :
1
01
101
0101
10101
13. Write a Java program to display the number rhombus structure. 

Test Data
Input the number: 7
Expected Output :

1
212
32123
4321234
543212345
65432123456
7654321234567
65432123456
543212345
4321234
32123
212
1
14. Write a Java program that reads a positive integer and count the number of digits the number (less
than ten billion) has. 10,000,000,000
Test Data
Input an integer number less than ten billion: 125463
Expected Output : 6
15. Write a program to calculate the factorial of number input by user
Test Data
Input an integer: 5
Expected Output : 120
16. Write a program to check whether a number input by user is prime or not.
17. Write a program to check whether a number input by user is Armstrong or not.
153=13+53+33
18. Write a program to count the number of upper case, lower case, digit and other character from a
string that is taken as input from user.
19. Write a program that takes two input from user: a floating point digit and a precision, and round off
and display the number to that precision.
Example:
input 13.3574 2
output: 13.36
20. Write a program that displays the amount entered by user in nepali money format.
Example:
input: 1242342
output: 1,24,342
21. Write a generalize program for Q20 by asking the format of money from user (e for English and n for
Nepali) and displaying formatted output accordingly.
input: 1242342
format: n
output: !@,$@,#$@
22. Write a program that prints n Fibonacci numbers, where n is input from user
Example:
input: 7
Output: 1 1 2 3 5 8 13
23. Write a program that prints nth Fibonacci number, where n is input from user
Example:
input: 7
Output: 13
24. Write a program that inputs arbitrary positive number from user and prints their sum. Program ends
when the input from user is negative.
25. Write a program in java that takes a 4-digit PIN from the user. The user should have a total of 3
attempts of putting in the PIN. If incorrect, the user should be warned with the remaining attempts.
P.S. Actual PIN is 5730
Output:
Please input the PIN: <take input>
Sorry, your PIN is incorrect. You have 2 attempts left.

26. Write a program HighLow.java that implements a simple guessing game High and Low. The program
selects a random number between 1 to 100. The player than tries to guess its value. After each, the
program gives a hint “higher” or “lower”. An execution might look like this:
Guess 1: 52
Hint: higher
Guess 2: 72
Hint: lower
Guess 3: 68
Correct after only 3 guesses – brilliant!!
The program is terminated after 10 guesses with a suitable comment. Use Scanner class to take
input from the user.

27. Write a short program that prints each number from 1 to 100 on a new line.
For each multiple of 3, print "Fizz" instead of the number.
For each multiple of 5, print "Buzz" instead of the number.
For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number.
28. Write a generalized program for question 21 that takes format as another input (e for English, n
for nepali), and display the money format as per user choice.
input: 1242342
format: e
output: 124,342
29. Write a program that converts the number entered in English to nepali.
input: 122.332
output: १२२.३३२
30. Write a Java program that reads in two floating-point numbers and tests whether they are the
same up to n decimal places, n input from user.
Test Data
Input floating-point number: 1.256355
Input floating-point another number: 1.25621312
precision: 3
Expected Output :
They are different
31. Write a Java program that reads in two integer numbers and tests whether they are the same up
to n position starting from the least position, n input by user.
Test Data
Input integer number: 123424256
Input integer another number: 3256
value of n: 3
Expected Output :
They are same
32.

You might also like