Question
import java.util.*; import java.math.RoundingMode; import java.text.DecimalFormat; class Easy { // Recursive function to return gcd of a and b public static int calcGCD(int a, int
import java.util.*;
import java.math.RoundingMode;
import java.text.DecimalFormat;
class Easy
{
// Recursive function to return gcd of a and b
public static int calcGCD(int a, int b)
{
if (b == 0)
return a;
return calcGCD(b, a % b);
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
char opt='#';int n;
while(opt!='0')
{
int correct=0,wrong=0;
System.out.println(" 1) Quotient 2) Least Common Multiple (LCM) 3) Greatest Common Multiple (GCD) 0) Quit");
opt=sc.next().charAt(0);
switch(opt)
{
case '1':
System.out.print("Number Of Question : ");
n=sc.nextInt();
for(int i=1;i
{
//generate random numbers between [0,150]
int num1 = (int)(Math.random() * (150 - 1 + 1) + 0);
//generate random numbers between [1,40]
int num2 = (int)(Math.random() * (40 - 1 + 1) + 1);
System.out.print("Q"+i+": "+num1+"/"+num2+" = ");
int ans=sc.nextInt();
int correctans=num1um2;
if(ans==correctans)
correct++;
else
wrong++;
}
System.out.println("You have entered "+n+" questions "+correct+" of them are correct. And your mark is "+df.format((double)(correct*100.0))+"%");
break;
case '2':
System.out.print("Number Of Questions : ");
n=sc.nextInt();
for(int i=1;i
{
//generate random numbers between [1,80]
int num1 = (int)(Math.random() * (80 - 1 + 1) + 1);
//generate random numbers between [2,30]
int num2 = (int)(Math.random() * (30 - 1 + 1) + 2);
System.out.print("Q"+i+": LCM ("+num1+","+num2+") = ");
int ans=sc.nextInt();
int correctans=(num1*num2)/calcGCD(num1,num2);
if(ans==correctans)
correct++;
else
wrong++;
}
System.out.println("You have entered "+n+" questions "+correct+" of them are correct. And your mark is "+df.format((double)(correct*100.0))+"%");
break;
case '3':
System.out.print("Number Of Questions : ");
n=sc.nextInt();
for(int i=1;i
{
//generate random numbers between [1,200]
int num1 = (int)(Math.random() * (200 - 1 + 1) + 1);
int num2 = (int)(Math.random() * (200 - 1 + 1) + 1);
System.out.print("Q"+i+": GCD ("+num1+","+num2+") = ");
int ans=sc.nextInt();
int correctans=calcGCD(num1,num2);
if(ans==correctans)
correct++;
else
wrong++;
}
System.out.println("You have entered "+n+" questions "+correct+" of them are correct. And your mark is "+df.format((double)(correct*100.0))+"%");
break;
case '0':
System.out.println("End of Quiz!!");
break;
default:
System.out.println("Invalid Input");
break;
}
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started