Skip to content

sangaryousmane/java-interview-questions

Repository files navigation

How to work with this repository

  • Clone the repository from here https://github.com/sangaryousmane/java-interview-questions.git
  • Navigate into the /src directory if you need the answers to all the questions but make sure to try the questions on your own first
  • The /src directory has subdirectories based on your need. For instance, there is a subdirectory for Basics, Arrays, Search Algorithms et al.
  • Make sure and practice more, don't copy and paste but type the codes instead.

Part I: Introduction to Java programming

Check all the manual of this part in this link: Here

Questions:

  1. Input a year and find whether it is a leap year or not.
  2. Take two numbers and print the sum of both.
  3. Take a number as input and print the multiplication table for it.
  4. Take 2 numbers as inputs and find their HCF and LCM.
  5. Keep taking numbers as inputs till the user enters ‘x’, after that print sum of all.

PART II: Write Java programs for the following:

Check all the manual of this part in this link: Here

Questions:

  1. Write a program to print whether a number is even or odd, also take input from the user.
  2. Take name as input and print a greeting message for that particular name.
  3. Write a program to input principal, time, and rate (P, T, R) from the user and find Simple Interest.
  4. Take in two numbers and an operator (+, -, *, /) and calculate the value. (Use if conditions)
  5. Take 2 numbers as input and print the largest number.
  6. Input currency in rupees and output in USD.
  7. To calculate Fibonacci Series up to n numbers.
  8. To find out whether the given String is Palindrome or not.
  9. To find Armstrong Number between two given number.

PART III: Basic Java Programs

Questions:

Check all the manual of this part in this link: Here

  1. Area Of Circle Java Program
  2. Area Of Triangle
  3. Area Of Rectangle Program
  4. Area Of Isosceles Triangle
  5. Area Of Parallelogram
  6. Area Of Rhombus
  7. Area Of Equilateral Triangle
  8. Perimeter Of Circle
  9. Perimeter Of Equilateral Triangle
  10. Perimeter Of Parallelogram
  11. Perimeter Of Rectangle
  12. Perimeter Of Square
  13. Perimeter Of Rhombus
  14. Volume Of Cone Java Program
  15. Volume Of Prism
  16. Volume Of Cylinder
  17. Volume Of Sphere
  18. Volume Of Pyramid
  19. Curved Surface Area Of Cylinder
  20. Total Surface Area Of Cube
  21. Fibonacci Series In Java Programs
  22. Subtract the Product and Sum of Digits of an Integer
  23. Input a number and print all the factors of that number (use loops).
  24. Take integer inputs till the user enters 0 and print the sum of all numbers (HINT: while loop)
  25. Take integer inputs till the user enters 0 and print the largest number from all.
  26. Addition Of Two Numbers

Intermediate Java Programs

  1. Factorial Program In Java
  2. Calculate Electricity Bill
  3. Calculate Average Of N Numbers
  4. Calculate Discount Of Product
  5. Calculate Distance Between Two Points
  6. Calculate Commission Percentage
  7. Power In Java
  8. Calculate Depreciation of Value
  9. Calculate Batting Average
  10. Calculate CGPA Java Program
  11. Compound Interest Java Program
  12. Calculate Average Marks
  13. Sum Of N Numbers
  14. Armstrong Number In Java
  15. Find Ncr & Npr
  16. Reverse A String In Java
  17. Find if a number is palindrome or not
  18. Future Investment Value
  19. HCF Of Two Numbers Program
  20. LCM Of Two Numbers
  21. Java Program Vowel Or Consonant
  22. Perfect Number In Java
  23. Check Leap Year Or Not
  24. Sum Of A Digits Of Number
  25. Kunal is allowed to go out with his friends only on the even days of a given month. Write a program to count the number of days he can go out in the month of August.
  26. Write a program to print the sum of negative numbers, sum of positive even numbers and the sum of positive odd numbers from a list of numbers (N) entered by the user. The list terminates when the user enters a zero.

Functions in Java

Questions

  1. Define two methods to print the maximum and the minimum number respectively among three numbers entered by the user.
  2. Define a program to find out whether a given number is even or odd.
  3. A person is eligible to vote if his/her age is greater than or equal to 18. Define a method to find out if he/she is eligible to vote.
  4. Write a program to print the sum of two numbers entered by user by defining your own method.
  5. Define a method that returns the product of two numbers entered by user.
  6. Write a program to print the circumference and area of a circle of radius entered by user by defining your own method.
  7. Define a method to find out if a number is prime or not.
  8. Write a program that will ask the user to enter his/her marks (out of 100). Define a method that will display grades according to the marks entered as below:

Marks Grade 91-100 AA 81-90 AB 71-80 BB 61-70 BC 51-60 CD 41-50 DD <=40 Fail 10. Write a program to print the factorial of a number by defining a method named 'Factorial'. Factorial of any number n is represented by n! and is equal to 1 * 2 * 3 * .... * (n-1) *n. E.g.-

4! = 1 * 2 * 3 * 4 = 24 3! = 3 * 2 * 1 = 6 2! = 2 * 1 = 2 Also, 1! = 1 0! = 1 12. Write a function to find if a number is a palindrome or not. Take number as parameter. 13. Convert the programs in flow of program, first java, conditionals & loops assignments into functions. 14. Write a function to check if a given triplet is a Pythagorean triplet or not. (A Pythagorean triplet is when the sum of the square of two numbers is equal to the square of the third number). 15. Write a function that returns all prime numbers between two given numbers. 16. Write a function that returns the sum of first n natural numbers.

Arrays In Java

Submit the following on your Leetcode profile itself.

Easy

  1. Build Array from Permutation
  2. Concatenation of Array
  3. Running Sum of 1d Array
  4. Richest Customer Wealth
  5. Shuffle the Array
  6. Kids With the Greatest Number of Candies
  7. Number of Good Pairs
  8. How Many Numbers Are Smaller Than the Current Number
  9. Create Target Array in the Given Order
  10. Check if the Sentence Is Pangram
  11. Count Items Matching a Rule
  12. Find the Highest Altitude
  13. Flipping an Image
  14. Cells with Odd Values in a Matrix
  15. Matrix Diagonal Sum
  16. Find Numbers with Even Number of Digits
  17. Transpose Matrix
  18. Add to Array-Form of Integer
  19. Maximum Population Year
  20. Determine Whether Matrix Can Be Obtained By Rotation
  21. Two Sum
  22. Find N Unique Integers Sum up to Zero
  23. Lucky Number In a Matrix
  24. Maximum Subarray
  25. Reshape the Matrix
  26. Plus One
  27. Remove Duplicates from Sorted Array
  28. Minimum Cost to Move Chips to The Same Position

Medium

  1. Spiral Matrix
  2. Spiral Matrix II
  3. Spiral Matrix III
  4. Set Matrix Zeroes
  5. Product of Array Except Self
  6. Find First and Last Position of Element in Sorted Array
  7. Jump Game
  8. Rotate Array
  9. Sort Colors
  10. House Robber
  11. Hard
  12. Max Value of Equation
  13. First Missing Positive
  14. Good Array

About

This repo is solely for java interview questions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published