Ad Code

Responsive Advertisement

JAVA

Java Practical Questions


Operators

  1. Write a program to add two numbers entered by the user.
  2. Write a program to swap two numbers using a third variable.
  3. Write a program to swap two numbers without using a third variable.
  4. Write a program to find the remainder when a number is divided by another number.
  5. Write a program to check if a number is even or odd using the modulus operator.
  6. Write a program to calculate the area of a rectangle using multiplication.
  7. Write a program to calculate the square of a number using the `*` operator.
  8. Write a program to compute the cube of a number using the `*` operator.
  9. Write a program to calculate the average of three numbers.
  10. Write a program to check whether two numbers are equal or not.

If-Else 

  1. Write a program to check whether a number is even or odd using if-else.
  2. Write a program to find the largest of two numbers using if-else.
  3. Write a program to find the largest of three numbers using nested if-else.
  4. Write a program to check whether a number is positive, negative, or zero.
  5. Write a program to check if a number is divisible by both 3 and 5.
  6. Write a program to find whether a character is a vowel or consonant.
  7. Write a program to check whether a number is prime or not.
  8. Write a program to check if a person is eligible to vote (18+ years).
  9. Write a program to determine whether a year is a leap year.
  10. Write a program to find the grade of a student based on marks.

Switch Case 

  1. Write a program to display the name of the day based on a number (1-7).
  2. Write a program to display the name of a month based on a number (1-12).
  3. Write a program to check if a given character is a vowel or consonant using switch.
  4. Write a program to find whether a character is uppercase, lowercase, or a digit.
  5. Write a program to perform basic arithmetic operations (+, -, *, /) using switch.
  6. Write a program to find whether a number is even or odd using switch.
  7. Write a program to classify a triangle as equilateral, isosceles, or scalene using switch.
  8. Write a program to determine the type of a vehicle based on user input.
  9. Write a program to categorize a person’s BMI as underweight, normal, overweight, or obese.
  10. Write a program to determine traffic light actions based on color input.

Loops

  1. Write a program to print numbers from 1 to 100 using a for loop.
  2. Write a program to print even numbers between 1 to 50 using a while loop.
  3. Write a program to find the sum of the first 10 natural numbers.
  4. Write a program to calculate the factorial of a number using a loop.
  5. Write a program to reverse a given number using a loop.
  6. Write a program to display the Fibonacci series up to n terms.
  7. Write a program to print all prime numbers from 1 to 100.
  8. Write a program to find the greatest common divisor (GCD) of two numbers.
  9. Write a program to print a multiplication table for a given number.
  10. Write a program to count the number of digits in a number.

Loops with Conditionals 

  1. Write a program to find the sum of even numbers from 1 to 100.
  2. Write a program to count the number of odd numbers between 1 and 100.
  3. Write a program to check if a number is a palindrome.
  4. Write a program to check if a number is an Armstrong number.
  5. Write a program to count the number of vowels in a given string.
  6. Write a program to check whether a number is prime or not.
  7. Write a program to find the sum of the digits of a given number.
  8. Write a program to calculate the sum of the first 50 prime numbers.
  9. Write a program to display all the factors of a given number.
  10. Write a program to find the largest digit in a given number.

Functions

  1. Write a function to find the sum of two numbers.
  2. Write a function to check if a number is prime.
  3. Write a function to swap two numbers.
  4. Write a function to calculate the factorial of a number.
  5. Write a function to reverse a given number.
  6. Write a function to find the maximum of two numbers.
  7. Write a function to find the minimum of two numbers.
  8. Write a function to compute the power of a number (x^y).
  9. Write a function to count the number of digits in a number.
  10. Write a function to find the sum of digits of a number.

Arrays 

  1. Write a program to declare and initialize an array.
  2. Write a program to find the largest element in an array.
  3. Write a program to find the smallest element in an array.
  4. Write a program to calculate the sum of elements in an array.
  5. Write a program to reverse an array.
  6. Write a program to copy elements from one array to another.
  7. Write a program to search for an element in an array.
  8. Write a program to sort an array in ascending order.
  9. Write a program to sort an array in descending order.
  10. Write a program to merge two sorted arrays.

Post a Comment

0 Comments