Java Programs for Practice with Solutions


1. Ramesh's basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

View Solution

2. The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.

View Solution

3. If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.

View Solution

4. Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.

View Solution

5. The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.

View Solution

6. Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

View Solution

7. If a five-digit number is input through the keyboard, write a program to reverse the number.

View Solution

8. If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. ( Hint: Use the modulus operator '%')

View Solution

9. If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number.

View Solution

10. In a town, the percentage of men is 52. The percentage of total literacy is 48. If total percentage of literate men is 35 of the total population, write a program to find the total number of illiterate men and women if the population of the town is 80,000.

View Solution

11. A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.

View Solution

12. If the total selling price of 15 items and the total profit earned on them is input through the keyboard, write a program to find the cost price of one item.

View Solution

13. If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example, if the number that is input is 12391 then the output should be displayed as 23402.

View Solution

14. Write a program to convert a string to an integer in Java

View Solution

15. Write a program to convert seconds to hour, minute and seconds

View Solution

16. Write Java program to Swap two numbers using bitwise operator

View Solution

17. Write Java program to demonstrate the example of the right shift (>>) operator

View Solution

18. Write Java program to demonstrate the example of the left shift (<<) operator

View Solution

19. Write Java program to Convert string to Boolean

View Solution

20. Write Java program to Perform subtraction without using minus (-) operator

View Solution

21. Write Java program to Calculate Perimeter of a Circle

View Solution

22. Write Java program to Calculate Area of a Circle

View Solution

23. Write Java program to Find Area of Rectangle

View Solution

24. Write Java program to Find Area of Triangle

View Solution

25. Write Java program to Calculate EMI

View Solution

26. Write Java program to how to accept Userinput from keyboard

View Solution

27. Write Java program to Extract Numbers from the string

View Solution

28. Write Java program to Get different input from user

View Solution




Basic Programs