You are on page 1of 3

1.

Write a program that takes two numbers as input from users and print the largest among
them.
2. Write a program that checks if the number input by user is odd or even and display message
accordingly
3. Write a program that checks if the number input by user is divisible by 5 or not and display
message accordingly
4. Write a program that checks if the number input by user is both even and divisible by 5 or
not and display message accordingly.
(Note: Do try to write an algorithm and flowchart first before writing your code. It will
help you understand the flow of program.)
Resources: https://www.edrawsoft.com/explain-algorithm-flowchart.html (skip types of
algorithm)
5. Write a program to test if the character input by user is upper case or lower case or other
character.
6. Write a program to convert the case of character input by user. For example, if the user
inputs character ‘x’, output must be ‘X’
7. Write a program to input the annual income from user and compute the tax according to the
given conditions and display the total tax:
Total Annual Taxable Income Tax Rate
Upto Rs.1,00,000 No tax
From 1,00,001 to 1,50,000 10% of the income exceeding Rs.1,00,000
From 1,50,000 to 2,50,000 Rs.5000 +20% of the income exceeding Rs.1,50,000
Above Rs.2,50,000 Rs.25,000 +30% of the income exceeding Rs.2,50,000

8. Write a program to check whether the year input by user in leap year or not.
9. An electronics shop has announced the following seasonal discounts on the purchase of
certain items.

Purchase Amount in Rs. Discount on Laptops Discount on Desktop PC


0 - 25,000 0.0% 5.0%
25,001 – 57,000 5.0% 7.5%
57,001 – 1,00,000 7.5% 10.0%
More than 1,00,000 10.0% 15.0%
Write a program based on the above criteria, to the purchase amount and the type of purchase, L
for laptop and D for desktop by a customer. Compute and print the net amount to be paid by a
customer.
Formula:
discount = (discount rate/100) * amount of purchase
net amount = amount of purchase – discount
10. Write a program to compute the area of a:
i. Rectangle (length * breadth)
ii. Circle (  * r2), use standard value for 
iii. Square (side * side)
Display a menu to output the area as per the user’s choice.
11. Declare and initialize three integer variables x, y and z as 15, 2 and 8. Arrange and print the
variables in ascending order.
12. Write a program to find whether a given character is a digit or a letter. Test your program.
13. Write a program to print the reverse of a 3-digit number input by user.
Example: if the number input by user is 325, then the output should be 523.
14. Write a program to find the sum of 3-digit number input by user.
Example: if the sum of 234 is 2+3+4=9.
15. Write a program to check whether the 3-digit number input by user is palindrome or not.
Example: 232 is palindrome since the number is same from forward and reverse direction
16. Write a program to check it a number input by user is Armstrong number or not
Example: 153 is Armstrong number since 13 +53 +33= 153
17. Write a program to print absolute value of a number entered by user. E.g.-
INPUT: 1 OUTPUT: 1
INPUT: -1 OUTPUT: 1
18. Write a Java program that input a number from the user and checks if the number is between
1-7 or not. If the number is not between 1-7, your program should make the number fall in
the range, then displays the name of the weekday.
Sample Output:
input: 4 Output: Wednesday
input 10 Output: Tuesday
(Use if else to check the range and switch case to display the week day.)
19. A student will not be allowed to sit in exam if his/her attendance is less than 75%.
Take following input from user
Number of classes held
Number of classes attended.
And print
percentage of class attended
Is student is allowed to sit in exam or not.
20. Modify the above question to allow student to sit if he/she has medical cause. Ask user if
he/she has medical cause or not ( 'Y' or 'N' ) and print accordingly.
21. Write a Java program to solve quadratic equations (use if, else if and else). Hint: The
equation is ax2 + bx + c=0, Take a, b, c as input from user. There are three nature of root of a
quadratic equation. imaginary, real and equal, real and unequal. Write complete code for all
possible cases. In case of imaginary number display the roots are imaginary (you need not
calculate the root).
−b ± √b 2−4 ac 2
Hint: x1,x2= , b -4ac is called determinant of the root
2a
a. if b2<4ac roots are imaginary
b. else if b2>4ac roots are real

22. Write a Java program that reads in two floating-point numbers and tests whether they are the
same up to three decimal places.
Test Data
Input floating-point number: 1.256355
Input floating-point another number: 1.25621312
Expected Output :
They are same
23. Write a Java program that reads in two integer numbers and tests whether they are the same
up to three position starting from the least position.
Test Data
Input integer number: 123424256
Input integer another number: 3256
Expected Output :
They are same
24. Write a program that takes two numbers as input from users and print the largest among them
using ternary operator.
25. Write a program that checks if the number input by user is odd or even and display message
accordingly using ternary operator
26. Write a program that checks if the number input by user is divisible by 5 or not and display
message accordingly using ternary operator
27. Write a program that checks if the number input by user is both even and divisible by 5 or
not and display message accordingly using ternary operator.
28. Write a program to check whether the year input by user in leap year or not using ternary
operator.
29. Write a program that takes three numbers as input from users and print the largest among
them using ternary operator.
30. Write a Java program to find the number of days in a month
Input a month number: 2
Input a year: 2016
February 2016 has 29 days
31. Write a program to input the three sides of triangle and check if the sides of triangle are valid
or not. If the triangle is valid, print its type (scalene, isosceles, equilateral)

You might also like