JAVA PROGRAM LIST FROM IF_ELSE LOOPS SWITCH ARRAYS
STRINGS CLASSES & OBJECTS
1. Check if a number is even or odd.
2. Check if a number is positive, negative, or zero.
3. Check if a number is divisible by 5 and 7.
4. Find the greatest of two numbers.
5. Find the greatest of three numbers.
6. Check whether a character is a vowel or consonant.
7. Check if a year is a leap year.
8. Accept age and check voting eligibility.
9. Accept marks and print grade (>=90: A+, >=75: A, etc.).
10. Check if a number is a multiple of 3 or 5.
11. Input 3 angles, check if they form a valid triangle.
12. Input 3 sides, check and classify the triangle
(equilateral/isosceles/scalene).
13. Accept cost price and selling price, check if it’s profit or loss and print
percentage.
14. *Accept two numbers and an operator (+, -, , /), use switch to perform the
operation.
15. Accept a day number (1-7) and print the day using switch.
16. Accept a character and check if it is uppercase/lowercase/digit/special
character.
17. Accept temperature in Celsius and display message (cold, warm, hot).
18. Accept salary and print net salary by applying allowances using if
conditions.
19. Accept a number and check whether it is a palindrome.
20. Accept a number and check if it’s an Armstrong number (3-digit only).
21. Check if a student passes (marks >= 35 in all subjects).
22. electricity bill using slab-based system:
• First 100 units: ₹2/unit
• Next 200 units: ₹3/unit
• Beyond that: ₹5/unit
• (use if-else-if ladder)
23. Calculate and display the bonus based on years of service.
24. Accept a digit (0–9) and print it in words using switch.
25. Check whether a number is a prime number using if.
26. Menu-driven program for:
• 1: Find square
• 2: Find cube
• 3: Find square root
• (Use switch-case)
27. Program to accept a student's percentage and assign a grade.
28. Accept a time in hours (24-hour format) and display greeting (Good morning,
afternoon...).
29. Check if a number is between 100 and 200.
30. Accept three subject marks and display:
• Average
• Total
• Result (pass/fail)
31. Check whether a number is a strong number.
(A number is strong if the sum of the factorial of its digits equals the number itself.
e.g., 145 → 1! + 4! + 5! = 145)
32. Check whether a number is a neon number.
(A neon number is a number where the sum of digits of its square is equal to the
number. e.g., 9 → 9² = 81 → 8 + 1 = 9)
33. Check whether a number is a spy number.
(A spy number is a number where the sum and product of digits are equal. e.g., 112
→ 1+1+2 = 4, 1×1×2 = 2)
34. Print all prime numbers in a given range (e.g., 50 to 100).
35. Find the HCF and LCM of two numbers using loops.
36. Display the sum of all even digits in a number.
37. Print numbers from 1 to N skipping multiples of 5.
38. Check if a number is an automorphic number.
(If square of number ends with the same number. e.g., 76² = 5776)
39. Find the largest and smallest digit in a number.
40. Display the count of odd and even digits in a number.
41. Generate and print the sum of the following series:
S = 1 + 1/2 + 1/3 + 1/4 + ... + 1/N
42. Find the sum of the following series:
S = x + x² + x³ + ... + xⁿ
(User inputs x and n)
43. Generate a decreasing pattern of stars using nested loops.
markdown
Copy
Edit
*****
****
***
**
44. Display the Fibonacci series up to a number N (limit-based).
45. Print the reverse of a string (entered by user using loops).
46. Count vowels and consonants in a word using loops.
47. Print all factors of a number.
48. Check whether a number is a perfect square (without Math.sqrt).
49. Find the sum of digits which are prime in a number.
50. Check if a number is a Kaprekar number.
(e.g., 45² = 2025 → 20 + 25 = 45)
51. Accept a string and print each character on a new line.
52. Count the total number of vowels and consonants in a string.
53. Check whether a given string is a palindrome.
(Same forwards and backwards, e.g., "madam")
54. Accept a string and count the number of words.
55. Accept a string and print it in reverse order.
56. Accept a string and count the number of uppercase and lowercase letters.
57. Accept a sentence and count the number of digits and special characters.
58. Accept a sentence and replace all vowels with '*'.
59. Accept a string and print only the first character of each word.
Input: "Java Is Fun" → Output: "J I F"
60. Accept a sentence and display the longest word.
61. Accept a string and convert all lowercase letters to uppercase.
62. Accept a string and check whether all characters are alphabets.
63. Check whether two strings are anagrams.
(Same letters in any order, e.g., "listen" and "silent")
64. Accept a sentence and remove all spaces.
65. Accept a sentence and print the frequency of each character.
66. Accept a sentence and print the frequency of each word.
67. Accept a string and sort the characters alphabetically.
68. Accept a sentence and print words that start with a vowel.
69. Check whether a string contains only digits.
70. Accept a string and print all duplicate characters.
71. Accept a sentence and display it in title case.
(First letter capitalized for each word)
72. Accept a sentence and count the number of punctuation marks.
73. Accept a sentence and replace a specific word with another word.
74. Accept a sentence and print words in reverse order.
Input: "ICSE is easy" → Output: "easy is ICSE"
75. Accept a string and remove all vowels.
76. Accept n integers into an array and display them.
77. Accept n numbers into an array and print the sum of elements.
78. Find the average of elements stored in an array.
79. Find the maximum and minimum values in an array.
80. Count how many elements are even and how many are odd.
81. Accept n numbers and search for a specific number (Linear Search).
82. Sort an array in ascending order using Bubble Sort.
83. Sort an array in descending order using Selection Sort.
84. Accept n elements and count how many are divisible by 3.
85. Accept an array and display all prime numbers.
86. Accept an array and reverse its contents.
87. Copy elements from one array to another.
88. Accept an array and remove duplicate elements.
89. Accept an array and shift elements to the right by one position.
90. Accept an array and insert an element at a specific position.
91. Accept an array and delete an element from a given index.
92. Accept marks of 10 students and count how many passed (marks ≥ 35).
93. Merge two arrays into a third array.
94. Find the second largest element in an array.
95. Find the frequency of each element in an array.
96. Accept an array and check if it is a palindrome.
97. Accept elements and display only the non-repeated elements.
98. Accept an array and print all elements greater than the average.
99. Accept scores and count how many students scored within 90–100 range.
100. Accept 10 integers and display how many are positive, negative, or zero.
101. Accept a 3x3 matrix and display it in matrix format.
102. Find the sum of all elements in a 2D array.
103. Find the sum of each row and each column in a 2D array.
104. Find the maximum and minimum element in a 2D array.
105. Print the principal diagonal elements of a square matrix.
106. Print the secondary (opposite) diagonal elements of a square matrix.
107. Find the sum of the principal diagonal elements.
108. Find the sum of the secondary diagonal elements.
109. Accept a 3x3 matrix and count how many elements are even and odd.
110. Accept a matrix and print only elements greater than a given value.
111. Find the transpose of a square matrix (interchange rows and columns).
112. Check whether a matrix is symmetric or not.
(A matrix is symmetric if A[i][j] == A[j][i])
113. Multiply two 3x3 matrices.
114. Accept a matrix and find the row with the maximum sum.
115. Accept a matrix and display the column with the smallest sum.
116. Accept a matrix and search for a specific element.
117. Check if all diagonal elements are prime numbers.
118. Accept a matrix and print the boundary elements.
119. Accept a 4x4 matrix and rotate it clockwise by 90 degrees.
120. Accept a matrix and replace all odd numbers with 0 and even with 1.
121. Define a class Student with data members: name, roll, and marks. Accept and
display them.
122. Create a class Rectangle with data members length and breadth. Accept them
and calculate area and perimeter.
123. Create a class Circle with radius. Accept radius and compute area and
circumference.
124. Define a class NumberCheck with a method to check whether a number is
even or odd.
125. Define a class PrimeCheck to check whether a given number is prime.
126. Create a class PalindromeCheck to check if a number is palindrome.
127. **Create a class ElectricBill with:
Name
Units consumed
Calculate bill using slab rates.**
128. Create a class BankAccount with name, account number, and balance.
Implement methods to deposit and withdraw.
129. Define a class FactorialCalc to calculate factorial of a number using a method.
130. Define a class FibonacciSeries to print N terms of Fibonacci using an object
method.
131. Create a class Result that accepts marks in 5 subjects, calculates total,
average, and grade.
132. Create a class ArmstrongCheck with a method to check if a number is
Armstrong.
133. Define a class PerfectNumber to check whether a number is perfect.
134. Create a class Employee to store employee name, ID, basic pay. Calculate
gross pay (basic + DA + HRA).
135. Create a class MenuDrivenMath with methods for square, cube, and square
root of a number.
136. Create a class ArrayStats to accept an array of integers and find max, min, and
average.
137. Create a class PalindromeString to check if a given string is a palindrome.
138. Create a class StringStats to count vowels, consonants, and digits in a string.
139. Create a class Matrix to accept and display a 2D array of integers.
140. Create a class TransposeMatrix to calculate and print transpose of a square
matrix.