ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2009 ICSE Computer Science Paper



Share with a Friend

Solved 2009 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Menu driven - BUZZ Number / GCD Program - ICSE 2009 Computer Science

Write a menu-driven program to accept a number from the user and check whether it is a BUZZ number or to accept any two numbers and print the GCD of them.
a) A BUZZ number is the number which either ends with 7 or is divisible by 7.
b) 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 until the remainder is zero. The divisor then results the GCD.

import java.util.Scanner; class Menu{ public static void main(String args[]){ Scanner in = new Scanner(System.in); System.out.println("1. Buzz number"); System.out.println("2. GCD"); System.out.print("Enter your choice: "); int choice = Integer.parseInt(in.nextLine()); switch(choice){ case 1: System.out.print("Enter the number: "); int n = Integer.parseInt(in.nextLine()); if(n % 7 == 0 || n % 10 == 7) System.out.println("Buzz number"); else System.out.println("Not a Buzz number"); break; case 2: System.out.print("First number: "); int a = Integer.parseInt(in.nextLine()); System.out.print("Second number: "); int b = Integer.parseInt(in.nextLine()); while(a % b != 0){ int rem = a % b; a = b; b = rem; } System.out.println("GCD = " + b); break; default: System.out.println("Invalid choice!"); } } }

Output

 
 OUTPUT 1: 
1. Buzz number
2. GCD
Enter your choice: 1
Enter the number: 17
Buzz number
 
 OUTPUT 2: 
1. Buzz number
2. GCD
Enter your choice: 2
First number: 24
Second number: 12
GCD = 12