Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Java Interview Question And Answers Pdf

Free Java Interview Question And Answers Pdf -Quiz -5

Posted on February 4, 2024March 14, 2025 By Updategadh No Comments on Free Java Interview Question And Answers Pdf -Quiz -5

Java Interview Question And Answers Pdf ( Quiz -4 )

  1. FizzBuzz: Write a program that prints the numbers from 1 to 100. But for multiples of three, print “Fizz” instead of the number, and for the multiples of five, print “Buzz.” For numbers that are multiples of both three and five, print “FizzBuzz.”

for i in range(1, 101):
    if i % 3 == 0 and i % 5 == 0:
        print("FizzBuzz")
    elif i % 3 == 0:
        print("Fizz")
    elif i % 5 == 0:
        print("Buzz")
    else:
        print(i)

  1. Palindrome Checker: Create a function that checks if a given word or phrase is a palindrome (reads the same backward as forward), ignoring spaces and punctuation.

def is_palindrome(word):
    cleaned_word = ''.join(char.lower() for char in word if char.isalnum())
    return cleaned_word == cleaned_word[::-1]

# Example usage:
word_to_check = "A man, a plan, a canal, Panama!"
print(is_palindrome(word_to_check))

  1. Factorial Calculation: Write a function to calculate the factorial of a non-negative integer entered by the user. The factorial of a number is the product of all positive integers up to that number.

def factorial(n):
    if n == 0 or n == 1:
        return 1
    else:
        return n * factorial(n-1)

# Example usage:
user_input = int(input("Enter a non-negative integer: "))
print(factorial(user_input))

  1. Sum of Even Numbers: Write a program that calculates the sum of all even numbers from 1 to a given user-specified limit.

def sum_even_numbers(limit):
    result = sum(i for i in range(2, limit+1, 2))
    return result

# Example usage:
user_limit = int(input("Enter the limit: "))
print(sum_even_numbers(user_limit))

Java Interview Question And Answers Pdf
Java Interview Question And Answers Pdf

  1. Guess the Number Game: Develop a simple number guessing game where the computer randomly selects a number between 1 and 100, and the user has to guess it. Provide hints such as “too high” or “too low” after each guess until the correct number is guessed.

import random

def guess_the_number():
    secret_number = random.randint(1, 100)
    guess = None

    while guess != secret_number:
        guess = int(input("Guess the number (between 1 and 100): "))
        
        if guess < secret_number:
            print("Too low! Try again.")
        elif guess > secret_number:
            print("Too high! Try again.")
        else:
            print(f"Congratulations! You guessed the correct number {secret_number}!")

# Example usage:
guess_the_number()


Java Interview Question And Answers Pdf ( Quiz -5 )


Prime Number Checker: Write a function to determine if a given positive integer is a prime number.

public class PrimeNumberChecker {
    public static boolean isPrime(int number) {
        if (number <= 1) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(number); i++) {
            if (number % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int userInput = 17; // Example input
        System.out.println(isPrime(userInput));
    }
}

Reverse a String: Create a program or function that takes a string as input and outputs the string in reverse order.

public class ReverseString {
    public static String reverseString(String input) {
        return new StringBuilder(input).reverse().toString();
    }

    public static void main(String[] args) {
        String inputString = "Hello, World!";
        System.out.println(reverseString(inputString));
    }
}

Check 100+ JAVA Spring Boot Projects with Source Code

Count Vowels and Consonants: Write a program or function that takes a string as input and counts the number of vowels and consonants in it.

public class CountVowelsConsonants {
    public static void countVowelsConsonants(String input) {
        int vowels = 0, consonants = 0;
        String lowerInput = input.toLowerCase();

        for (char ch : lowerInput.toCharArray()) {
            if (ch >= 'a' && ch <= 'z') {
                if ("aeiou".contains(String.valueOf(ch))) {
                    vowels++;
                } else {
                    consonants++;
                }
            }
        }

        System.out.println("Vowels: " + vowels);
        System.out.println("Consonants: " + consonants);
    }

    public static void main(String[] args) {
        String userInput = "Programming is Fun!";
        countVowelsConsonants(userInput);
    }
}

Sum of Digits: Create a function that calculates the sum of the digits of a given positive integer.

public class SumOfDigits {
    public static int sumOfDigits(int number) {
        int sum = 0;
        while (number != 0) {
            sum += number % 10;
            number /= 10;
        }
        return sum;
    }

    public static void main(String[] args) {
        int userInput = 12345; // Example input
        System.out.println(sumOfDigits(userInput));
    }
}

Check 50+ JAVA Projects with Source Code

Pattern Printing – Right Triangle: Write a program to print a right-angled triangle pattern using asterisks (*) where the height of the triangle is determined by user input.

import java.util.Scanner;

public class RightTrianglePattern {
    public static void printRightTriangle(int height) {
        for (int i = 1; i <= height; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print("* ");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the height of the right-angled triangle: ");
        int userHeight = scanner.nextInt();
        printRightTriangle(userHeight);
        scanner.close();
    }
}

E-Commerce Website Project in Java
E-Commerce Website Project in Java

Latest Post :-

Keyword
java interview question and answers pdf
java interview question and answer pdf
java interview question
java interview question on string
java interview question and answers for freshers
java interview question on collection
java interview question book
java interview question and answer for fresher pdf
java interview question for 2 years experience
core java interview question
design patterns in java interview question
what is classloader in java interview question
java interview question pdf download
java interview question pdf free download
java interview question and answer for experienced
java interview question and answer for 3 years experience

Post Views: 782
Interview Question Tags:Interview Question

Post navigation

Previous Post: Free Source Code : Farming Application using Java and Firebase
Next Post: Free Source Code: Resume Building Websites Project in PHP

More Related Articles

Accenture Previous Papers 2023 Accenture Previous Papers 2025 : A Comprehensive Guide Interview Question
Best Project Ideas for Beginner Students - Best Project Ideas for Beginner Students Best Project Ideas for Beginner Students Interview Question
Top 10 C and C++ Project Ideas for Beginners - Top 10 C and C++ Project Ideas for Beginners Top 10 C and C++ Project Ideas for Beginners Interview Question

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. How to build an AI System Step-By-Step Guide [ Create an Ai ]
  2. Top 30 Coding Interview Questions You Should Know !
  3. Free Java Interview Question And Answers Pdf [Quiz -7]
  4. Top 20 Web Application Interview Questions
  5. Swift Interview Questions and Answers: A Comprehensive Guide
  6. Popular Java Coding Questions & Answer for 2025

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,612)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,209)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,859)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme