Simple Logical Program And Java Core Interview questions

interview questions.

1-WAP find factorial of a given number using java .

a -by using loop

b-find factorial of a given number using recursion

2- WAP reverse the number in java.

3-WAP reverse the String in java.

4- WAP palindrome number program .

5- WAP find max number in array .

6- WAP find min number in array .

7-WAP to sort array in java .

B-Sort By using Arrays.sort(array)

8-WAP Find Second largest number in array.

we need to sort array than we can find K’th element .

9 WAP to find duplicate in array .

10- WAP How to create custom arraylist in java.

a- ArrayList is a re-sizable array

Testing Class

B-It is used to fetch the element from the particular position of the list.

11 -Can I add StringBuffer objects in TreeSet ?

if you want to add StringBuffer in TreeSet .we need follow some rule .
1- Object should be homogeneous
2- Object Should be comparable.

String is comparable ,But StringBuffer is not a comparable.

How to solve this problem ?

We need to create custom sorting logic by using comparator Interface and then use it in your TreeSet as follows:

12 -WAP to sort array accordingly ……

input array : -[90,10,40,20,30,60,50,70,80]
Output sequence : 90,10,80,20,70,30,60,40,50

Step 1 — we need to sort this array

int[] box = { 90, 10, 40, 20, 30, 60, 50, 70, 80 };

Step 2

Step 3 — Logic


13- WAP to Sort basic on two attribute.

Sort on the basic of salary but if two employee salary has been same then it sort on the basic of name .

Question 1

By using Java 8

Sort basic on two attribute


Example of Java 7 —

Custom Logic


15- WAP Int to String in java .

Ques -How do I retrieve only string objects from heterogeneous ArrayList in Java?

16-WAP Capitalize the first letter in and and print them on a single line, separated by a space.

Example :

Hello Java

17 WAP nested if condition Condision

Ques -18 How to Read n number String

Program // For loop 
public static void main(String[] args) {
Scanner scan = new Scanner(;
for(int i = 1; scan.hasNext()== true; i++){
System.out.println(i + " " + scan.nextLine());

// While loop System
public static void main(String[] args) {
Scanner scan = new Scanner(;
int i = 0;
System.out.println(i + " " + scan.nextLine());

Java||Spring-Boot Micro services Application developer||India ||node js || angular