java questions
java questions
Basic Level:
1. Write a program to print "Hello, World!" if a variable message is
equal to "greetings".
2. Write a program to print "Even" if a number is even and "Odd" if a
number is odd.
3. Write a program to print the highest of three numbers.
4. Write a program to check whether a number is divisible by 5.
5. Write a program to check whether a given character is a vowel or
a consonant.
6. Write a program to check whether a given year is a leap year or
not.
7. Write a program to print the sum of all even numbers from 1 to
100.
8. Write a program to print the multiplication table of a given
number.
9. Write a program to find the largest element in an array.
10. Write a program to find the second largest element in an
array.
Medium Level:
11. Write a program to find the sum of all numbers divisible by 3
or 5 from 1 to 100.
12. Write a program to check whether a given string is a
palindrome or not.
13. Write a program to find the factorial of a given number using
a for loop.
14. Write a program to find the Fibonacci series up to a given
number.
15. Write a program to remove all duplicates from an array.
16. Write a program to sort an array in ascending order.
17. Write a program to sort an array in descending order.
18. Write a program to find the common elements between two
arrays.
19. Write a program to find the union of two arrays.
20. Write a program to find the intersection of two arrays.
High Level:
21. Write a program to implement binary search on a sorted
array.
22. Write a program to implement linear search on an unsorted
array.
23. Write a program to find the GCD and LCM of two numbers.
24. Write a program to find all prime numbers between 1 and
100.
25. Write a program to find the prime factors of a given number.
26. Write a program to implement bubble sort on an array.
27. Write a program to implement selection sort on an array.
28. Write a program to implement insertion sort on an array.
29. Write a program to implement merge sort on an array.
30. Write a program to implement quick sort on an array.
31. Write a program to convert a decimal number to binary.
32. Write a program to convert a binary number to decimal.
33. Write a program to convert a decimal number to hexadecimal.
34. Write a program to convert a hexadecimal number to decimal.
35. Write a program to implement a stack data structure using an
array.
Basic Level:
1. Write a program to find the sum of all odd numbers from 1 to 100.
2. Write a program to check whether a given number is positive,
negative, or zero.
3. Write a program to print the ASCII value of a given character.
4. Write a program to print the reverse of a given string.
5. Write a program to find the length of a given string.
6. Write a program to check whether a given string contains a
particular substring.
7. Write a program to print the first 10 terms of the geometric
series 1, 2, 4, 8, 16, ...
8. Write a program to print the first 10 terms of the arithmetic
series 1, 3, 5, 7, 9, ...
9. Write a program to find the sum of the first n terms of the
arithmetic series 1, 3, 5, 7, 9, ...
10. Write a program to find the sum of the first n terms of the
geometric series 1, 2, 4, 8, 16, ...
Medium Level:
1. Write a program to find the sum of all numbers in an array.
2. Write a program to find the product of all numbers in an array.
3. Write a program to find the average of all numbers in an array.
4. Write a program to find the median of an array.
5. Write a program to find the mode of an array.
6. Write a program to reverse the elements of an array.
7. Write a program to rotate the elements of an array to the left by
one position.
8. Write a program to rotate the elements of an array to the right by
one position.
9. Write a program to find the second smallest element in an array.
10. Write a program to implement binary search on an array of
integers.
******************************************************************
********
1. Write a Java program that checks if a given number is positive or negative
using if/else statement.
2. Write a Java program that checks if a given number is even or odd using
if/else statement.
3. Write a Java program that checks if a given number is a prime number
using if/else statement.
4. Write a Java program that checks if a given year is a leap year using
if/else statement.
5. Write a Java program that checks if a given character is a vowel or
consonant using if/else statement.
6. Write a Java program that checks if a given string is a palindrome using
if/else statement.
7. Write a Java program that checks if a given number is a perfect square
using if/else statement.
8. Write a Java program that checks if a given string contains all the vowels
using if/else statement.
9. Write a Java program that determines the grade of a student based on
their score using if/else statement.
10. Write a Java program that determines the largest of three numbers
using if/else statement.
11. Write a Java program that determines the smallest of three numbers
using if/else statement.
12. Write a Java program that converts a given temperature from
Celsius to Fahrenheit using if/else statement.
13. Write a Java program that calculates the area of a circle or square
based on user input using switch statement.
14. Write a Java program that determines the day of the week based on
user input using switch statement.
15. Write a Java program that determines the number of days in a
month based on user input using switch statement.
16. Write a Java program that determines the name of a month based
on its number using switch statement.
17. Write a Java program that determines the number of days in a year
based on user input using switch statement.
18. Write a Java program that determines the name of a shape based on
user input using switch statement.
19. Write a Java program that determines the number of sides in a
shape based on user input using switch statement.
20. Write a Java program that determines the name of a color based on
its code using switch statement.
I hope these questions give you some ideas for practicing if/else
statement and switch statement in Java. Let me know if you have any
other questions!
give me 30 questions on Control Structures
Sure, here are 30 questions on control structures in Java:
1. Write a Java program that prints the numbers from 1 to 100 using a for
loop.
2. Write a Java program that prints the sum of the numbers from 1 to 100
using a for loop.
3. Write a Java program that prints the even numbers from 1 to 100 using a
for loop.
4. Write a Java program that prints the prime numbers from 1 to 100 using a
for loop.
5. Write a Java program that prints the Fibonacci sequence up to a given
number using a for loop.
6. Write a Java program that prints a multiplication table up to a given
number using nested loops.
7. Write a Java program that calculates the factorial of a given number using
a for loop.
8. Write a Java program that checks if a given number is a palindrome using
a while loop.
9. Write a Java program that checks if a given number is a perfect number
using a while loop.
10. Write a Java program that calculates the sum of the digits of a given
number using a while loop.
11. Write a Java program that prints the numbers from 1 to 100 using a
while loop.
12. Write a Java program that prints the sum of the numbers from 1 to
100 using a while loop.
13. Write a Java program that prints the even numbers from 1 to 100
using a while loop.
14. Write a Java program that prints the prime numbers from 1 to 100
using a while loop.
15. Write a Java program that prints the Fibonacci sequence up to a
given number using a while loop.
16. Write a Java program that prints a multiplication table up to a given
number using do-while loop.
17. Write a Java program that calculates the factorial of a given number
using a do-while loop.
18. Write a Java program that checks if a given number is a palindrome
using a for loop.
19. Write a Java program that checks if a given number is a perfect
number using a for loop.
20. Write a Java program that calculates the sum of the digits of a given
number using a for loop.
21. Write a Java program that uses nested loops to print a pattern of
asterisks.
22. Write a Java program that uses nested loops to print a pattern of
numbers.
23. Write a Java program that uses nested loops to print a pyramid of
asterisks.
24. Write a Java program that uses nested loops to print a diamond of
asterisks.
25. Write a Java program that uses nested loops to print a right-angled
triangle of asterisks.
26. Write a Java program that uses nested loops to print a rectangle of
asterisks.
27. Write a Java program that uses nested loops to print a hollow
rectangle of asterisks.
28. Write a Java program that uses nested loops to print a triangle of
numbers.
29. Write a Java program that uses nested loops to print a pyramid of
numbers.
30. Write a Java program that uses nested loops to print a multiplication
table.