Java Practice Questions for Java Candidates
Logical coding questions are designed to evaluate a candidate’s ability to write clean code, understand core Java concepts, and apply logical reasoning to solve problems. These questions help interviewers assess the candidate’s skills in variables, operators, loops, conditionals, arrays, strings, functions, and basic algorithms.
Below is an organized overview of the most commonly asked logical coding questions for beginners to intermediate Java candidates.
Basic Program
- Write a Java program to print “Hello World”.
-
Write a Java program to perform addition, subtraction, multiplication, and division of two numbers.
-
Write a Java program to calculate the area of a circle, rectangle, and square.
-
Write a Java program to find the square and cube of a given number.
-
Write a Java program to take user input and display full name, age, college name, and address.
-
Write a Java program to read and print an integer value.
-
Write a Java program to take two numbers as input from the user and swap them using a temporary variable.
-
Write a Java program to take two numbers as input from the user and perform arithmetic operations.
-
Write a Java program to swap two numbers without using a temporary variable.
-
Write a Java program to take a number as input and find its square and cube.
-
Write a Java program to input the length and width of a rectangle from the user and calculate its area and perimeter.
Hint
Use the following formulas:
Area of a rectangle = length × width
Perimeter of a rectangle = 2 × (length + width)
- Write a java program to input the radius of a circle from the user and calculate its circumference and area.
Hint
Use the following formulas:
Circumference of a circle = 2×𝜋×𝑟
Area of a circle = π×r×r
-
Write a Java program to input the principal amount (P), time period (T), and rate of interest (R) from the user and calculate the simple interest.
Hint
Use the formula for Simple Interest:
Simple Interest (SI) = (P*T*R)/100
-
Write a Java program to take an employee’s salary as input, increase it by 20%, and display the updated total salary.
Hint
Use the following formula:
Increased Salary = Salary + (Salary × 20 / 100)
Conditional Statement
-
Check whether a number is an Armstrong number
-
Write a Java program to check whether a number is a Perfect number.
-
Check whether a number is Prime
-
Write a Java program to print all Prime numbers within a given range.
-
Write a Java program to check whether a vowel is present in a string.
-
Create a menu-driven program and Perform arithmetic Operation using switch case
Loops
-
Write a Java program to generate the Fibonacci series up to a given number.
-
Write a Java program to find the factorial of a given number.
-
Write a Java program to reverse a given number.
-
Write a Java program to check whether a number is a Palindrome.
-
Write a Java program to find the sum of digits of a given integer.
-
Write a Java program to sort numbers in ascending order.
Pattern Design – Java Assignment Questions
- Write a Java program to print a number pattern in increasing order.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
- Write a Java program to print a number pattern with repeated numbers in each row.
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
- Write a Java program to print a continuous number triangle (Floyd’s Triangle).
1
2 3
4 5 6
7 8 9 10
- Write a Java program to print a centered number pyramid.
1
1 2
1 2 3
1 2 3 4
- Write a Java program to print a binary number pattern.
1
0 1
1 0 1
0 1 0 1
Array
-
Write a Java program to find the sum of all elements in an array.
-
Write a Java program to take marks of 5 subjects as input from the user, store them in an array, and calculate the total marks, percentage, and grade.
Hint
Total Marks = Sum of all subject marks
Percentage = (Total Marks / 500) × 100
-
Find the average of array elements
-
Count even and odd numbers in the array
-
Write a Java program to reverse the elements of an array.
-
Write a Java program to find the square of each element in an array.
-
Write a Java program to find the cube of each element in an array.
-
Write a Java program to perform addition of two arrays.
-
Write a Java program to perform addition, subtraction, and multiplication of two arrays.
-
Write a Java program to find the minimum and maximum elements in an array.
-
Write a Java program to find the second highest number in an array.
-
Write a Java program to find the second smallest number in an array.
-
Write a Java program to find duplicate elements in an array.
-
Write a Java program to remove duplicate elements from an array.
-
Write a Java program to perform addition of two 2D arrays.
-
Write a Java program to find the transpose of a matrix.
Sorting and Searching
-
Write a Java program to perform Linear Search on an array to find a given element.
-
Write a Java program to perform Binary Search on a sorted array to find a given element.
-
Write a Java program to sort an array of integers in ascending order using Bubble Sort.
-
Write a Java program to sort an array of integers in descending order using Selection Sort.
-
Write a Java program to sort an array of integers using Insertion Sort.
-
Write a Java program to sort an array of strings in alphabetical order.
-
Write a Java program to find the largest and smallest elements in an array using sorting.
-
Write a Java program to find the second largest element in an array using sorting.
-
Write a Java program to merge two sorted arrays into a single sorted array.
String
-
Write a Java program to check whether a string is a Palindrome.
-
Write a Java program to check whether two strings are anagrams.
-
Write a Java program to find duplicate characters in a string.
-
Write a Java program to find the frequency of duplicate characters in a string.
-
Write a Java program to find the frequency of each character in a string.
-
Write a Java program to remove duplicate characters from a string.
-
Write a Java program to reverse a string.
-
Write a Java program to reverse a string without using built-in functions.
-
Write a Java program to reverse each word in a string.
-
Write a Java program to read a sentence from the user and count the number of words.
-
Write a Java program to count the total number of characters in a string.
-
Write a Java program to count the number of vowels and consonants in a string.
-
Write a Java program to find duplicate words in a string (sentence).
-
Write a Java program to remove whitespace from a string.
Inharitance
- Write a programm to demostrate Single Inharitance in java?
- Write a programm to demostrate Multilevel Inharitance in java?
- Write a programm to demostrate Hierarchical Inharitance in java?
.png)