i want questions of 10 programs of switch case in BlueJ
Answers
import java.io.*;
class questionEIGHT2009
{
public static void main(String args[]) throws IOException
{
int i,j;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("**************MENU*************");
System.out.println("Type 1 to check if a number is a BUZZ number or not");
System.out.println("Type 2 to print GCD of any two numbers");
System.out.println("Enter your choice");
int ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println("Enter the number to check if it is buzz number or number");
int n=Integer.parseInt(br.readLine());
if(n%7==0 || n%10==7)
{
System.out.println("The number " +n+ " is a BUZZ number");
}
else
{
System.out.println("The number " +n+ " is NOT a BUZZ number");
}
break;
case 2:
System.out.println("Enter any two numbers to print their GCD");
int n1=Integer.parseInt(br.readLine());
int n2=Integer.parseInt(br.readLine());
int divisor, dividend;
if(n1>n2)
{
dividend=n1;
divisor=n2;
}
else
{
dividend=n2;
divisor=n1;
}
int rem=1;
while(rem!=0)
{
rem=dividend%divisor;
if(rem==0)
{
System.out.println("GCD is = " +divisor);
}
else
{
dividend=divisor;
divisor=rem;
}
}
break;
default:
System.out.println("Wrong choice");
}
}
}