Kiran Academy
Java Programming Batch Programs
Simple Programs
1. Write a program to find the sum of two integers.
2. Write a program to accept selling price and cost price and find the profit or loss.
3. Write a program to calculate average of three integer nos.
4. Write a program to accept two integers and find its addition, subtraction, multiplication
and division.
5. Write a program to accept the radius and find area of circle.
6. Write a program to accept marks of 5 subjects, calculate total, average, and display
percentage.
7. Write a program to print the multiplication table of a given number.
8. Write a Java program to print the cube of a given number.
9. Write a Java program to swap two numbers using a third variable.
10. Write a Java program to swap two numbers without using a third variable.
11. Write a Java program to convert temperature from Celsius to Fahrenheit.
12. Write a Java program to convert temperature from Fahrenheit to Celsius.
13. Write a Java program to print the ASCII value of a given character.
Control Statements (If..else, switch)
14. Write a program to accept a number and find it is even or odd.
15. Write a program to accept a number and find it Zero, Positive or Negative.
16. Write a program to accept two number and find smallest no.
17. Write a program to accept three number and find largest no.
18. Write a program to accept a year check whether it is Leap Year or not.
19. Write a program to accept a day of week(int) and display the weekday (e.g – day=4 →
Thursday) (use switch case).
20. Write a program to accept a character and check whether it is a vowel or consonant.
21. Write a program to accept a year and check whether it is a Leap Year or not.
22. Write a program to accept a day of the week (int) and display the weekday (use switch
case).
23. Write a Java program to count the number of vowels in a string.
24. Write a Java program to count the number of consonants in a string.
25. Write a Java program to calculate the square root of a number.
26. Write a Java program to calculate the cube root of a number.
27. Write a Java program to calculate simple interest.
28. Write a Java program to calculate compound interest.
29. Write a Java program to convert kilometers into meters, centimeters, and millimeters.
30. Write a Java program to convert days into years, weeks, and days.
31. Write a Java program to convert hours into minutes and seconds.
For Loop
32. Write a Java program to print all numbers from n down to 1.
33. Write a Java program to print the squares of numbers from 1 to n.
34. Write a Java program to print the characters from ‘A’ to ‘Z’.
35. Write a Java program to print the characters from ‘a’ to ‘z’.
36. Write a Java program to print the digits from 0 to 9 using a loop.
37. Write a Java program to print all factors of a given number.
38. Write a Java program to find the sum of all even digits from a given number.
39. Write a Java program to find the sum of all odd digits from a given number.
40. Write a Java program to print the multiplication tables from 1 to 10.
41. Write a Java program to calculate the power of a number (a^b).
42. Generate the Series 2 4 6 8 10 …..18 20.
43. Generate the Series 1 -2 3 -4 5 -6 7 -8 9 -10.
44. Generate the Series 1 10 100 1000.
45. Generate the Series 0 1 3 6 10 15 21 27 35..
46. Print 1 to 100 numbers prime numbers.
47. Generate the series 1 4 9 16 25 36 49 64 81 100.
48. Generate the series 3 6 9 12 15 18 21 24 27 30.
49. Fibonacci Series 0 1 1 2 3 5 8 13 21.
50. Generate the series 1 2 3 4 5 4 3 2 1.
51. Generate the series 1 10 100 1000 100 10 1.
52. Generate the Series 2 1 3 4 2 9 6 3 27.
53. Write a Java program to print the factorial series (1!, 2!, 3!, … n!).
54. Write a Java program to calculate the sum of the factorial series (1! + 2! + 3! … n!).
55. Write a Java program to accept 10 numbers and count how many are positive, negative,
or zero.
56. Write a Java program to accept 10 numbers and find the largest and smallest among
them.
Pattern Programs
57. 1
12
123
58. 11111
22222
33333
44444
55555
59. 1
12
123
1234
12345
60. 1
23
456
61. #####
@@@@@
#####
62. #####
#***#
#####
63. ABCDE
ABCD
ABC
AB
A
While Loop
64. Write a program to accept a number and find factorial using while loop.
65. Write a program to accept number and print the sum of digit. (e.g. N=1234 → 10).
66. Write a program to accept number and print the count of digit. (e.g. N=1234 → 4 digit).
67. Write a program to accept number and print the reverse of that number. (e.g. N=1234 →
4321).
68. Write a program to accept number and check whether the number is palindrome or not.
(e.g. N=4334 → palindrome no.).
69. Write a program to accept number and check whether the number is Armstrong or not.
(e.g. N=153 → (1)^3+(5)^3 +(3)^3=153).
70. Write a program to accept a number and print all its factors.
71. Write a program to accept two numbers and find their HCF (GCD).
72. Write a program to accept two numbers and find their LCM.
73. Write a program to print the Fibonacci series up to n terms.
74. Write a program to accept a number and print the sum of the first n natural numbers.
75. Write a program to accept a number and print the sum of squares of the first n natural
numbers.
Array
76. Write a program to accept a array and find its sum of elements.
77. Write a program to accept a array and print only even nos.
78. Write a program to accept a array and print sum of even nos.
79. Write a program to accept a array and print reverse array.
80. Write a program to accept a array and print array in ascending order.
81. Write a program to accept a array and print only prime nos array.
82. Find elements divisible by 5 and 7 in given array. (Input: 30 35 45 70 8 2 → Output:
35,70).
83. Find smallest no of given array (e.g. 3 5 4 7 8 2).
84. Find the missing no from given array (1 2 4 5 6 7 8 → Output: 3).
85. Find the square of all array elements given array.
86. Find unique (not repeated) elements in array.
87. Find second smallest and second biggest number in array without sorting.
88. Write a program to count the frequency of each element in an array.
89. Write a program to accept an array and remove duplicate elements.
90. Write a program to accept an array and find the largest and smallest element.
91. Write a program to accept an array and search for a given element (linear search).
String
92. Enter a string from user and find the length of string.
93. Enter a string from user and print it in UPPER case.
94. Enter a string from user and print it in Lower case.
95. Enter a string from user and print only vowels of string.
96. Enter 2 strings from user and concat them.
97. String s = "Kiran Academy" … print only vowels of string.
98. Enter 2 strings from user and find the max string.
99. Enter 2 strings from user and print reverse string.
100. Write a program in java to check whether the entered character is alphabet, digit or
symbol (use ASCII table).
101. Enter a string and print all characters using charAt().
102. Find frequency of each character in string.
103. Find strings which last two characters are same.
104. Find strings with more than 1 vowel.
105. Write a program to count the number of vowels, consonants, digits, and spaces in a
string.
106. Write a program to accept a string and check whether it is a palindrome or not.
107. Write a program to accept a string and print the reverse of the string without using
built-in functions.
108. Write a program to accept a string and remove all spaces from it.
109. Write a program to accept a string and remove all vowels from it.
Class and Object
110. Create a class Student details (roll_no, name, percentage). Accept and display
student records using methods.
111. Create a class Employee (emp_id, emp_name, age, salary). Accept and display
employee records.
112. Create a class Student details and accept 3 student records using constructor.
113. Create a class Mobile (model_no, model_name, cost). Accept 5 mobiles using
constructor and array of objects.
114. Create a class Student details with roll_no, name, and 5 subject marks. Calculate
total and percentage.
Inheritance
115. Create Customer → Depositor → Borrower classes for bank system (details of
deposits and loans).
116. Create Cricket_Player class to accept 10 players and display average runs.
117. Create Employee class with getSalary() method, extend it with Manager class to add
HRA and DA.
118. Create an interface Shape with area() and volume() methods. Implement it in
Rectangle, Circle, Triangle.
Collections
119. Read n Student names into ArrayList and display in Ascending order.
120. Read n Strings into ArrayList and iterate.
121. Enter N strings until 'STOP' and display them.