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;
        }
       
    }  
}

Comments

Popular posts from this blog

5th sem OOPJ Write an interactive program to print a diamond shape. For example, if user enters the number 3, the diamond will be as follows:

SQL Lab1: Create a Database Table for DayCare

SQL Lab 11