0% found this document useful (0 votes)
2 views16 pages

Java Question Set

The document contains a comprehensive set of programming exercises primarily focused on Java, covering various topics such as loops, functions, arrays, strings, pointers, and control structures. Each section includes specific tasks, ranging from printing patterns and calculating sums to implementing algorithms for number theory and string manipulation. Additionally, there are bonus exercises and adaptations for pointer concepts in Java, emphasizing the language's unique characteristics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Java Question Set

The document contains a comprehensive set of programming exercises primarily focused on Java, covering various topics such as loops, functions, arrays, strings, pointers, and control structures. Each section includes specific tasks, ranging from printing patterns and calculating sums to implementing algorithms for number theory and string manipulation. Additionally, there are bonus exercises and adaptations for pointer concepts in Java, emphasizing the language's unique characteristics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

JAVA QUESTION SET

1. Print all natural numbers from 1 to n using a while loop.


2. Print all natural numbers in reverse (from n to 1) using a while loop.

3. Print all alphabets from 'a' to 'z' using a while loop.

4. Print all even numbers between 1 and 100 using a while loop.

5. Print all odd numbers between 1 and 100 using a while loop.

6. Find the sum of all natural numbers between 1 and n.

7. Find the sum of all even numbers between 1 and n.

8. Find the sum of all odd numbers between 1 and n.

9. Print the mul plica on table of any number n.

10. Count the number of digits in a number.

11. Find the first and last digit of a number.

12. Find the sum of the first and last digit of a number.

13. Swap the first and last digits of a number.

14. Calculate the sum of digits of a number.

15. Calculate the product of digits of a number.

16. Enter a number and print its reverse.

17. Check whether a number is a palindrome or not.

18. Find the frequency of each digit in a given integer.

19. Enter a number and print it in words. (Example: 123 -> One Two Three)

20. Print all ASCII characters with their decimal values.

21. Find the power of a number using a for loop.

22. Find all factors of a number.

23. Calculate factorial of a number.

24. Find HCF (GCD) of two numbers.

25. Find LCM of two numbers.

26. Check whether a number is prime or not.

27. Print all prime numbers between 1 and n.

28. Find the sum of all prime numbers between 1 and n.


29. Find all prime factors of a number.

30. Check whether a number is an Armstrong number.

31. Print all Armstrong numbers between 1 and n.

32. Check whether a number is a Perfect number.

33. Print all Perfect numbers between 1 and n.

34. Check whether a number is a Strong number.

35. Print all Strong numbers between 1 and n.

36. Print Fibonacci series up to n terms.

37. Find one’s complement of a binary number.

38. Find two’s complement of a binary number.

39. Convert Binary to Octal number system.

40. Convert Binary to Decimal number system.

41. Convert Binary to Hexadecimal number system.

42. Convert Octal to Binary number system.

43. Convert Octal to Decimal number system.

44. Convert Octal to Hexadecimal number system.

45. Convert Decimal to Binary number system.

46. Convert Decimal to Octal number system.

47. Convert Decimal to Hexadecimal number system.

48. Convert Hexadecimal to Binary number system.

49. Convert Hexadecimal to Octal number system.

50. Convert Hexadecimal to Decimal number system.

51. Print Pascal’s triangle up to n rows.

52. Print star pa erns (like triangle, square, diamond).

53. Print number pa erns (like increasing, decreasing sequences).

Bonus:

 Write a program to print the X star pa ern.

 Write a program to print the Rhombus star pa ern.

 Write a program to print the Diamond star pa ern


Star Pa ern Ques ons (Added from h ps://codeforwin.org/c-programming/star-pa erns-
program-in-c)

54. Print Square Star Pa ern

Example for n=4:

markdown

CopyEdit

****

****

****

****

55. Print Hollow Square Star Pa ern

markdown

CopyEdit

****

* *

* *

****

56. Print Right-Angled Triangle Star Pa ern

markdown

CopyEdit

**

***

****

57. Print Right-Angled Hollow Triangle Star Pa ern

markdown

CopyEdit

**

**
****

58. Print Inverted Right-Angled Triangle Star Pa ern

markdown

CopyEdit

****

***

**

59. Print Inverted Hollow Right-Angled Triangle Star Pa ern

markdown

CopyEdit

****

**

60. Print Pyramid Star Pa ern

markdown

CopyEdit

***

*****

*******

61. Print Hollow Pyramid Star Pa ern

markdown

CopyEdit

**

* *

*******

62. Print Inverted Pyramid Star Pa ern

markdown

CopyEdit
*******

*****

***

63. Print Hollow Inverted Pyramid Star Pa ern

markdown

CopyEdit

*******

* *

**

64. Print Diamond Star Pa ern

markdown

CopyEdit

***

*****

***

65. Print Hollow Diamond Star Pa ern

markdown

CopyEdit

**

* *

**

66. Print Right Pascal Star Pa ern

markdown

CopyEdit

*
**

***

****

***

**

67. Print Hollow Right Pascal Star Pa ern

markdown

CopyEdit

**

**

****

**

**

68. Print Hollow Diamond Inside Rectangle Star Pa ern

Example for n=7:

markdown

CopyEdit

*******

* * *

****

** **

****

* * *

*******

69. Print Sandglass Star Pa ern

markdown

CopyEdit

*******
*****

***

***

*****

*******

70. Print Hollow Sandglass Star Pa ern

markdown

CopyEdit

*******

* *

**

**

* *

*******

Number Pa ern Programs (Inspired by h ps://codeforwin.org/c-programming/number-pa ern-


programs-in-c)

71. Print Floyd’s Triangle

Example for n=5:

CopyEdit

23

456

7 8 9 10

11 12 13 14 15

72. Print Inverted Floyd’s Triangle

CopyEdit
12345

6789

10 11 12

13 14

15

73. Print Number Pyramid

markdown

CopyEdit

22

333

4444

55555

74. Print Number Pyramid (with spaces)

markdown

CopyEdit

121

12321

1234321

123454321

75. Print Half Pyramid using numbers

yaml

CopyEdit

12

123

1234

12345

76. Print Inverted Half Pyramid using numbers

yaml
CopyEdit

12345

1234

123

12

77. Print Number Triangle

yaml

CopyEdit

22

333

4444

55555

78. Print Triangle using digits of row number (like above)

79. Print Pyramid of numbers increasing by 1 each me in a row

CopyEdit

23

456

7 8 9 10

80. Print Square Number Pa ern

CopyEdit

12345

12345

12345

12345

12345

81. Print Number Pa ern with 0 and 1 alterna ng in rows

CopyEdit

1
10

101

1010

10101

82. Print Right-Aligned Number Pyramid

markdown

CopyEdit

12

123

1234

12345

83. Print Right-Aligned Inverted Number Pyramid

markdown

CopyEdit

12345

1234

123

12

84. Print Diamond Number Pa ern

markdown

CopyEdit

212

32123

4321234

543212345

4321234

32123

212
1

85. Print Number Diamond with spaces

markdown

CopyEdit

22

3 3

4 4

5 5

4 4

3 3

22

86. Print Pascal’s Triangle Number Pa ern (alterna ve to 51)

87. Print Spiral Number Pa ern (complex)

Func on-Based Programming Exercises (Inspired by h ps://codeforwin.org/c-


programming/func ons-programming-exercises-and-solu ons-in-c)

88. Write a func on to check whether a number is even or odd.

89. Write a func on to find the maximum of two numbers.

90. Write a func on to find the maximum of three numbers.

91. Write a func on to check whether a number is prime.

92. Write a func on to calculate the factorial of a number.

93. Write a func on to calculate the sum of natural numbers up to n.

94. Write a func on to find the power of a number (x^y).

95. Write a func on to print Fibonacci series up to n terms.

96. Write a func on to check whether a number is palindrome.

97. Write a func on to find the GCD of two numbers.

98. Write a func on to find the LCM of two numbers.


99. Write a func on to reverse a number.

100. Write a func on to count the number of digits in a number.

101. Write a func on to swap two numbers using call by reference.

102. Write a func on to check whether a number is Armstrong number.

103. Write a func on to print all prime numbers between 1 and n.

104. Write a func on to find the sum of digits of a number.

105. Write a func on to convert decimal to binary.

106. Write a func on to convert binary to decimal.

107. Write a func on to find the sum of digits recursively.

108. Write a func on to calculate the nth term of an arithme c progression.

109. Write a func on to calculate the nth term of a geometric progression.

110. Write a recursive func on to calculate factorial.

111. Write a recursive func on to print Fibonacci series.

112. Write a recursive func on to reverse a string.

Array Programming Exercises (Inspired by h ps://codeforwin.org/c-programming/array-


programming-exercises-and)

113. Write a program to find the largest element in an array.

114. Write a program to find the smallest element in an array.

115. Write a program to find the sum of all elements in an array.

116. Write a program to find the average of elements in an array.

117. Write a program to copy all elements from one array to another.

118. Write a program to reverse the elements of an array.

119. Write a program to find the second largest element in an array.

120. Write a program to sort an array in ascending order.

121. Write a program to sort an array in descending order.

122. Write a program to find the frequency of each element in an array.

123. Write a program to find the union of two arrays.

124. Write a program to find the intersec on of two arrays.


125. Write a program to find the difference between two arrays.

126. Write a program to check whether an array is palindrome or not.

127. Write a program to merge two arrays.

128. Write a program to count the number of even and odd elements in an array.

129. Write a program to find the pair of elements whose sum is equal to a given number.

130. Write a program to find the missing number in an array of size n containing numbers from 1 to
n+1.

131. Write a program to remove duplicates from an array.

132. Write a program to rotate an array by k posi ons.

133. Write a program to find the leaders in an array (elements greater than all elements to their
right).

134. Write a program to find the equilibrium index of an array.

135. Write a program to find the maximum sum subarray (Kadane’s algorithm).

String Programming Exercises (Inspired by h ps://codeforwin.org/c-programming/string-


programming-exercises-and-solu ons-in-c)

136. Write a program to find the length of a string.

137. Write a program to reverse a string.

138. Write a program to check whether a string is palindrome.

139. Write a program to count vowels and consonants in a string.

140. Write a program to count the occurrence of each character in a string.

141. Write a program to convert a string to uppercase.

142. Write a program to convert a string to lowercase.

143. Write a program to compare two strings without using library func ons.

144. Write a program to concatenate two strings.

145. Write a program to find the frequency of a given character in a string.

146. Write a program to check whether two strings are anagrams.

147. Write a program to remove all white spaces from a string.

148. Write a program to find the largest word in a string.

149. Write a program to count the number of words in a string.


150. Write a program to find all permuta ons of a string.

151. Write a program to check whether a string contains only digits.

152. Write a program to replace all spaces with a given character in a string.

153. Write a program to find the first non-repea ng character in a string.

154. Write a program to remove duplicate characters from a string.

155. Write a program to find the longest palindrome substring in a string.

Pointer Programming Exercises Adapted for Java (Inspired by h ps://codeforwin.org/c-


programming/pointer-programming-exercises-and-solu ons-in-c)

156. Write a program to swap two numbers using pointers.

In Java: Use method call with wrapper classes or arrays to simulate.

157. Write a program to find the length of a string using pointers.

In Java: Use char array traversal or String methods.

158. Write a program to copy one string to another using pointers.

In Java: Use character array copy or StringBuilder.

159. Write a program to compare two strings using pointers.

In Java: Manual char-by-char comparison.

160. Write a program to concatenate two strings using pointers.

In Java: Use StringBuilder or manual array copy.

161. Write a program to find the sum of elements of an array using pointers.

In Java: Use array indexing.

162. Write a program to reverse a string using pointers.

In Java: Manual swapping in char array.

163. Write a program to insert an element in an array using pointers.

In Java: Use array or ArrayList manipula on.

164. Write a program to delete an element from an array using pointers.

In Java: Use ArrayList remove or manual shi .

165. Write a program to find the maximum element in an array using pointers.

In Java: Iterate through array.

166. Write a program to find the minimum element in an array using pointers.
167. Write a program to find the frequency of elements in an array using pointers.

168. Write a program to perform pointer arithme c for traversing an array.

In Java: Use array index incremen ng.

169. Write a program to demonstrate the use of void pointer (generic references).

In Java: Use Object references.

170. Write a program to swap two numbers using call by reference (simulate pointers).

Note on Java and Pointers

Java does not support pointers explicitly for safety reasons, but you can simulate pointer-like
behavior by:

 Passing references (objects, arrays) to methods.

 Using wrapper classes for primi ves.

 Manipula ng arrays or objects to emulate memory manipula on.

Switch-Case Programming Exercises (Inspired by h ps://codeforwin.org/c-programming/switch-


case-programming-exercise)

171. Write a program to print the day of the week based on the given number (1 to 7).

172. Write a program to find the number of days in a month using switch-case.

173. Write a program to perform basic calculator opera ons (+, -, *, /) using switch-case.

174. Write a program to check whether a character is a vowel or consonant using switch-case.

175. Write a program to find the grade of a student based on marks using switch-case.

176. Write a program to print the name of the month based on the month number.

177. Write a program to convert a number (1 to 4) to its equivalent season name using switch-case.

178. Write a program to check if a number is even or odd using switch-case.

179. Write a program to print the day type (weekday/weekend) based on the day number using
switch-case.

180. Write a program to find the quarter of the year based on the month number.

If-Else Programming Exercises (Inspired by h ps://codeforwin.org/c-programming/if-else-


programming-prac ce)
181. Write a program to check whether a number is posi ve or nega ve.

182. Write a program to find the largest of two numbers.

183. Write a program to find the largest of three numbers.

184. Write a program to check whether a number is even or odd.

185. Write a program to check whether a character is alphabet or not.

186. Write a program to check whether a character is uppercase or lowercase.

187. Write a program to check whether a year is leap year or not.

188. Write a program to check whether a number is divisible by 5 and 11 or not.

189. Write a program to check whether a number is divisible by 5 or 11.

190. Write a program to check whether a character is vowel or consonant.

191. Write a program to check whether a triangle is valid or not based on its angles.

192. Write a program to check whether a triangle is equilateral, isosceles or scalene.

193. Write a program to find the roots of a quadra c equa on.

194. Write a program to calculate profit or loss based on cost price and selling price.

195. Write a program to check whether a student has passed or failed based on marks.

196. Write a program to check whether an alphabet is vowel or consonant using if-else.

197. Write a program to check whether a number is divisible by 2 and 3.

198. Write a program to check whether a number is divisible by 7 or 11.

199. Write a program to check whether a number is a three-digit number or not.

200. Write a program to check whether a character is a digit or not.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy