Java Program For Student


Average of three number



Calculate Area of a Circle



Factorial Calculation



Check if a Number is Prime



Fibonacci Series



Palindrome Check



Sum of Digits



Matrix Addition



Reverse a String



Armstrong Number Check



Binary to Decimal Conversion



Factorial using Recursion


import java.util.Scanner;

public class FactorialRecursion {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = scanner.nextInt();

        long factorial = calculateFactorial(num);

        System.out.println("The factorial of " + num + " is: " + factorial);
        scanner.close();
    }

    private static long calculateFactorial(int num) {
        if (num == 0 || num == 1) {
            return 1;
        } else {
            return num * calculateFactorial(num - 1);
        }
    }
}


Check Leap Year



Write a program to enter two numbers and check whether they are co-prime or not.


Below is a Java program that takes two numbers as input and checks whether they are co-prime or not. Two numbers are considered co-prime if their greatest common divisor (GCD) is 1.


Explanation:
The program uses a method calculateGCD to find the greatest common divisor (GCD) of two numbers using the Euclidean Algorithm.
The main method takes two numbers as input from the user.
It then calls the calculateGCD method to find the GCD of the two numbers.
If the GCD is 1, the numbers are considered co-prime, and a message is displayed indicating that. Otherwise, a message is displayed indicating that the numbers are not co-prime.
The Scanner is closed to prevent resource leaks.
This program demonstrates a simple approach to check whether two numbers are co-prime or not.


Write a program to display all the ‘Buzz Numbers’ between p and q (where p<q). A ‘Buzz Number’ is the number which ends with 7 or is divisible by 7.


Below is a Java program that displays all the “Buzz Numbers” between p and q (where p is less than q). A “Buzz Number” is defined as a number that either ends with 7 or is divisible by 7.


The program starts by taking input values for p and q from the user.
It then validates the input to ensure that q is greater than p. If not, it prints an error message and terminates the program.
The isBuzzNumber method checks if a given number is a Buzz Number according to the definition provided (ends with 7 or is divisible by 7).
The displayBuzzNumbers method iterates through the numbers from p to q and prints the Buzz Numbers.
The main method calls these methods to execute the program. It prompts the user for input, validates it, and then displays the Buzz Numbers within the specified range.

 

    Leave a Reply

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