5th sem OOPJ Write a program to enter two numbers and perform mathematical operations on them.
import java.text.*;
import java.util.*;
/**
*
* @author Yash
*/
class pra3{
public static void main(String arg[]){
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
double a,b;
System.out.println("Select '+' '-' '*' '/' ");
System.out.print("Enter the value of a : ");
a = sc.nextDouble();
System.out.print("Enter the value of b : ");
b = sc.nextDouble();
System.out.println("Select you choice:");
String cho = sc1.nextLine();
switch(cho){
case "+" :
System.out.println("You have selected addition ");
System.out.println("Your Answer is : "+(a+b));
break;
case "-":
System.out.println("You have selected subtraction ");
System.out.println("Your Answer is : "+(a-b));
break;
case "/":
System.out.println("You have selected division ");
System.out.println("Your Answer is : "+(a/b));
break;
case "*":
System.out.println("You have selected multiplication ");
System.out.println("Your Answer is : "+(a*b));
break;
default:
System.out.println("You have selected Wrong choice");
break;
}
}
}
import java.util.*;
/**
*
* @author Yash
*/
class pra3{
public static void main(String arg[]){
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
double a,b;
System.out.println("Select '+' '-' '*' '/' ");
System.out.print("Enter the value of a : ");
a = sc.nextDouble();
System.out.print("Enter the value of b : ");
b = sc.nextDouble();
System.out.println("Select you choice:");
String cho = sc1.nextLine();
switch(cho){
case "+" :
System.out.println("You have selected addition ");
System.out.println("Your Answer is : "+(a+b));
break;
case "-":
System.out.println("You have selected subtraction ");
System.out.println("Your Answer is : "+(a-b));
break;
case "/":
System.out.println("You have selected division ");
System.out.println("Your Answer is : "+(a/b));
break;
case "*":
System.out.println("You have selected multiplication ");
System.out.println("Your Answer is : "+(a*b));
break;
default:
System.out.println("You have selected Wrong choice");
break;
}
}
}
Comments
Post a Comment