Experiment 1
Experiment 1
public class Q1
{
public static void main(String[] args)
{
double x,y;
Scanner scanner = new Scanner(System.in);
while(true)
{
System.out.println("Enter the choice:\n1. Calculate\n2. Exit");
int n = scanner.nextInt();
if(n==2)
{
System.out.println("Thanks for using our calculator!!");
scanner.close();
System.exit(1);
}
double ans;
switch(op)
{
case "+":
ans = x + y;
System.out.println("Sum of "+x+" and "+y+" is "+ans);
break;
case "-":
ans = x - y;
System.out.println("Subtraction of "+x+" and "+y+" is "+ans);
break;
case "*":
ans = x * y;
System.out.println("Multiplication of "+x+" and "+y+" is "+ans);
break;
case "/":
ans = x / y;
System.out.println("Division of "+x+" and "+y+" is "+ans);
break;
case "%":
ans = x % y;
System.out.println("Remainder of "+x+" and "+y+" is "+ans);
break;
default:
System.out.println("You entered wrong input");
break;
}
System.out.println("\n\n");
}
}
}
Q.2 WAP to find all prime numbers between a given range of values as long as
the user wants.
import java.util.*;
public class Q2 {
public static void main(String[] args) {
while(true)
{
System.out.println("Enter the choice:\n1. Calculate\n2. Exit");
int n = scan.nextInt();
if(n==2)
{
System.out.println("Thanks for using our calculator!!");
scan.close();
System.exit(1);
}
System.out.println("Enter the lower limit: ");
int lower = scan.nextInt();
System.out.println("Enter the upper limit: ");
int upper = scan.nextInt();
System.out.println("\nPrime numbers between the given limits are :");
System.out.println("\n\n");
}
}
}
}
}
else{
System.out.printf("%-15s00%d\n",s1,x);
}
}
System.out.println("================================");
}
}