Have a Question?

If you have any question you can ask below or enter what you are looking for!

Top 100 Java Fresher programing Interview Question


Top 100 Java Fresher programing Interview Question
Top 100 Java Fresher programing Interview Question
1. Write a program to read a String value from user and display it
package com.java4us;

import java.util.Scanner;

public class Program01 {

    public static void main(String[] args) {
        System.out.println("---Read a String value and display---");
        System.out.println("Please enter input value:- ");
        Scanner scanner = new Scanner(System.in);
        String input = scanner.next();
        System.out.println("Enter input value is: " + input);
    }
}
2. Write a program to read a integer value from user and display it
package com.java4us;

import java.util.Scanner;

public class Program02 {
    public static void main(String[] args) {
        System.out.println("---Read a integer value and display---");
        System.out.println("Please enter input value:- ");
        Scanner scanner = new Scanner(System.in);
        Integer input_value = scanner.nextInt();
        System.out.println("User input value is: " + input_value);
    }
}
3. Write a program to read a String value from user and display its individual charactor
package com.java4us;

import java.util.Scanner;

public class Program03 {

    public static void main(String[] args) {
        System.out.println("---Read a String value and display its individual charactor---");
        System.out.println("Please enter input value:- ");
        Scanner scanner = new Scanner(System.in);
        String input_value = scanner.next();
        for (int i = 0; i < input_value.length(); i++) {
            System.out.println(i + " charactor of given input is:- " + input_value.charAt(i));

        }
    }
}
4. Write a program to read one char value from user and display it
package com.java4us;

import java.util.Scanner;

public class Program04 {
    public static void main(String[] args) {
        System.out.println("---Read a String value and display first charactor---");
        System.out.println("Please enter input value:- ");
        Scanner scanner = new Scanner(System.in);
        char first_char = scanner.next().charAt(0);
        System.out.println("First charactor of given input is:- " + first_char);
    }
}
5. Write a program to read two numbers and swap them using third variable
package com.java4us;

import java.util.Scanner;

public class Program05 {
    public static void main(String[] args) {
        System.out.println("---Swaping with using Third variable---");
        System.out.println("Please enter First value:- ");
        Scanner scanner1 = new Scanner(System.in);
        int value1 = scanner1.nextInt();
        System.out.println("Please enter Second value:- ");
        Scanner scanner2 = new Scanner(System.in);
        int value2 = scanner2.nextInt();
        System.out.println("Value before swaping: " + value1 + "-" + value2);
        int temp = 0;
        temp = value1;
        value1 = value2;
        value2 = temp;
        System.out.println("Value after swaping: " + value1 + "-" + value2);
    }
}
6. Write a program to read two numbers and swap them without using third variable
package com.java4us;

import java.util.Scanner;

public class Program06 {
    public static void main(String[] args) {
        System.out.println("---Swaping without using Third variable---");
        System.out.println("Please enter first value");
        Scanner scannner1 = new Scanner(System.in);
        int value1 = scannner1.nextInt();
        System.out.println("Please enter second value");
        Scanner scannner2 = new Scanner(System.in);
        int value2 = scannner2.nextInt();
        System.out.println("Input value before swaping:- " + value1 + ":" + value2);
        value1 = value1 + value2;
        value2=value1-value2;
        value1 = value1 - value2;
        System.out.println("Input value after swaping:- " + value1 + ":" + value2);
        
    }
}
7. Write a program to read two numbers and swap them using bitwise operator
package com.java4us;

import java.util.Scanner;

public class Program07 {

    public static void main(String[] args) {
        System.out.println("---Swaping using bitwise operator---");
        System.out.println("Please enter first value");
        Scanner scannner1 = new Scanner(System.in);
        int value1 = scannner1.nextInt();
        System.out.println("Please enter second value");
        Scanner scannner2 = new Scanner(System.in);
        int value2 = scannner2.nextInt();
        System.out.println("Input value before swaping:- " + value1 + ":" + value2);
        value1 = value1 ^ value2;
        value2 = value1 ^ value2;
        value1 = value1 ^ value2;
        System.out.println("Input value after swaping:- " + value1 + ":" + value2);
    }
}
8. Write a program to read two numbers and display sum.
package com.java4us;

import java.util.Scanner;

public class Program08 {
    public static void main(String[] args) {
        System.out.println("---Read two number and display sum of those two number---");
        System.out.println("Please enter first value");
        Scanner scannner1 = new Scanner(System.in);
        int value1 = scannner1.nextInt();
        System.out.println("Please enter second value");
        Scanner scannner2 = new Scanner(System.in);
        int value2 = scannner2.nextInt();
        System.out.println("Sum of user entered value:- " + (value1 + value2));
    }
}
9. Write a program to read two number and display sum without using + Operator
package com.java4us;

import java.util.Scanner;

public class Program09 {
    public static void main(String[] args) {
        System.out.println("---Read two number and display sum without using airthmetic operator---");
        System.out.println("Please enter first value");
        Scanner scannner1 = new Scanner(System.in);
        int value1 = scannner1.nextInt();
        System.out.println("Please enter second value");
        Scanner scannner2 = new Scanner(System.in);
        int value2 = scannner2.nextInt();
        while (value2 != 0) {

            int carry = value1 & value2;

            value1 = value1 ^ value2;

            value2 = carry << 1;
        }
        System.out.println("sum = " + value1);
    }
}
10. Write a program to convert Fahrenheit to Celsius
package com.java4us;

import java.util.Scanner;

public class Program10 {
    public static void main(String[] args) {
        System.out.println("---Program to convert fahrenheit to Celsius---");
        Scanner scanner = new Scanner(System.in);
        System.out.println("Please enter fahrenheit value");
        int fahrenheit = scanner.nextInt();
        int Celsius = (fahrenheit - 32) * 5 / 9;
        System.out.println("Celsious value for corresponding fahrenheit " + fahrenheit + " value is :- " + Celsius);
    }
}
11. Write a program to read a number and display whether the number is positive or nagative.
package com.java4us;

import java.util.Scanner;

public class Program11 {
    public static void main(String[] args) {
        System.out.println("---Program to check user entered value is Positive or Negative---");
        System.out.println("Please enter the value");
        Scanner scanner = new Scanner(System.in);
        int value = scanner.nextInt();
        if (value >= 0) {
            System.out.println("Entered value is Positive " + value);
        } else
            System.out.println("Entered value is Negetive " + value);
    }
}
12. Write a program to read age of person and display whether he/she eligible for voting or not
package com.java4us;

import java.util.Scanner;

public class Program12 {
    public static void main(String[] args) {
        System.out.println("---Program to check user is eligible for voting or not---");
        System.err.println("Please enter your current age");
        Scanner scanner = new Scanner(System.in);
        int age = scanner.nextInt();
        if (age >= 18) {
            System.out.println("You are eligible for vote");
        } else
            System.out.println("You are not eligble for vote");
    }
}
13. Write a program to read number and display whether the number is even or odd.
package com.java4us;

import java.util.Scanner;

public class Program13 {
    public static void main(String[] args) {
        System.out.println("---Program to check user entered value is even or odd---");
        System.out.println("Please enter value");
        Scanner scanner = new Scanner(System.in);
        int value = scanner.nextInt();
        if (value % 2 == 0) {
            System.out.println("User entered value is even");
        } else
            System.out.println("User entered value is odd");
    }
}
14. Write a program to read two number and display the maximum.
package com.java4us;

import java.util.Scanner;

public class Program14 {
    public static void main(String[] args) {
        System.out.println("---Program to check maximum digit from two enter value---");
        System.out.println("Please enter first digit");
        Scanner scanner = new Scanner(System.in);
        int value1 = scanner.nextInt();
        System.out.println("Please enter second digit");
        int value2 = scanner.nextInt();
        if (value1 < value2) {
            System.out.println(value2 + " is greater then value " + value1);
        } else if (value1 > value2) {
            System.out.println(value1 + " is greater then value " + value2);
        } else
            System.out.println(value1 + " both are equal " + value2);
    }
}
15. Write a program to read two number and display the minimum.
package com.java4us;

import java.util.Scanner;

public class Program15 {

    public static void main(String[] args) {
        System.out.println("---Program to check minimum digit from two enter value---");
        System.out.println("Please enter first digit");
        Scanner scanner = new Scanner(System.in);
        int value1 = scanner.nextInt();
        System.out.println("Please enter second digit");
        int value2 = scanner.nextInt();
        if (value1 < value2) {
            System.out.println(value1 + " is less then value " + value2);
        } else if (value1 > value2) {
            System.out.println(value2 + " is less then value " + value1);
        } else
            System.out.println(value1 + " both are equal " + value2);
    }
}
16. Write a program to read three numbers and display the maximum.
package com.java4us;

import java.util.Scanner;

public class Program16 {
    public static void main(String[] args) {
        System.out.println("---Program to read three digit and display maximum---");
        System.out.println("Please enter first digit");
        Scanner scanner = new Scanner(System.in);
        int value1 = scanner.nextInt();
        System.out.println("Please enter second digit");
        int value2 = scanner.nextInt();
        System.out.println("Please enter third digit");
        int value3 = scanner.nextInt();
        if (value1>value2&&value1>value3) {
            System.out.println(value1+" is maximum value");
        }
        else if (value2 > value1 && value2 > value3) {
            System.out.println(value2+" is maximum value");
        }
        else
            System.out.println(value3 + " is maximum value");
    }
}
17. Write a program to read three numbers and display the minimum.
package com.java4us;

import java.util.Scanner;

public class Program17 {

    public static void main(String[] args) {
        System.out.println("---Program to read three digit and display minimum---");
        System.out.println("Please enter first digit");
        Scanner scanner = new Scanner(System.in);
        int value1 = scanner.nextInt();
        System.out.println("Please enter second digit");
        int value2 = scanner.nextInt();
        System.out.println("Please enter third digit");
        int value3 = scanner.nextInt();
        if (value1 < value2 && value1 < value3) {
            System.out.println(value1 + " is minimum value");
        } else if (value2 < value1 && value2 < value3) {
            System.out.println(value2 + " is minimum value");
        } else
            System.out.println(value3 + " is minimum value");
    }
}
18. Write a program to read a char and display whether it is digit or not.
package com.java4us;

import java.util.Scanner;

public class Program18 {

    public static void main(String[] args) {
        System.out.println("---Program to read a charactor and check whether its a digit or not---");
        System.out.println("Please enter charactor value");
        Scanner scanner = new Scanner(System.in);
        char ch = scanner.next().charAt(0);
        if (ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122) {
            System.out.println("Enter digit is charactor");
        } else
            System.out.println("Enter digit is not charactor");
    }
}
19. Write a program to read a char and display whether it is uppercase alphabet or not.
package com.java4us;

import java.util.Scanner;

public class Program19 {

    public static void main(String[] args) {
        System.out.println("---Program to read a charactor and check whether its a uppercase alphabet or not---");
        System.out.println("Please enter charactor value");
        Scanner scanner = new Scanner(System.in);
        char ch = scanner.next().charAt(0);
        if (ch >= 65 && ch <= 90) {
            System.out.println("Enter digit is Upper case alphabet");
        } else
            System.out.println("Enter digit is not Upper case alphabet");
    }
}
20. Write a program to read a char and display whether it is lowercase alphabet or not.
package com.java4us;

import java.util.Scanner;

public class Program20 {

    public static void main(String[] args) {
        System.out.println("---Program to read a charactor and check whether its a lowercase alphabet or not---");
        System.out.println("Please enter charactor value");
        Scanner scanner = new Scanner(System.in);
        char ch = scanner.next().charAt(0);
        if (ch >= 97 && ch <= 122) {
            System.out.println("Enter digit is Lower case alphabet");
        } else
            System.out.println("Enter digit is not lower case alphabet");
    }
}