Computer Applications
Write a menu driven program to access a number from the user and check whether it is a BUZZ number or to accept any two numbers and to print the GCD of them.
- A BUZZ number is the number which either ends with 7 or is divisible by 7.
- GCD (Greatest Common Divisor) of two integers is calculated by continued division method. Divide the larger number by the smaller; the remainder then divides the previous divisor. The process is repeated till the remainder is zero. The divisor then results the GCD.
Answer
import java.util.Scanner;
public class KboatBuzzGCD
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("1. Buzz number");
System.out.println("2. Calculate GCD");
System.out.print("Enter your choice: ");
int choice = in.nextInt();
switch (choice) {
case 1:
System.out.print("Enter a number: ");
int num = in.nextInt();
if (num % 10 == 7 || num % 7 == 0)
System.out.println(num + " is a Buzz Number");
else
System.out.println(num + " is not a Buzz Number");
break;
case 2:
System.out.print("Enter first number: ");
int a = in.nextInt();
System.out.print("Enter second number: ");
int b = in.nextInt();
while (b != 0) {
int t = b;
b = a % b;
a = t;
}
System.out.println("GCD = " + a);
break;
default:
System.out.println("Incorrect Choice");
break;
}
}
}Output
Related Questions
Write a program to input a number and print whether the number is a special number or not. (A number is said to be a special number, if the sum of the factorial of the digits of the number is same as the original number).
Write a menu driven program to accept a number from the user and check whether it is a Prime number or an Automorphic number.
(a) Prime number: (A number is said to be prime, if it is only divisible by 1 and itself)
Example: 3,5,7,11
(b) Automorphic number: (Automorphic number is the number which is contained in the last digit(s) of its square.)
Example: 25 is an Automorphic number as its square is 625 and 25 is present as the last two digits.
Write a program in Java to find the sum of the given series:
x1 + x2 + x3 + x4 … + xn
Write a program in Java to find the sum of the given series:
x1 - x2 + x3 - x4 … - xn , where x = 3