Write JAVA Program To Use Functions of Calculator (Using Switch)....



I/P:-



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package TUTschool;

import java.util.Scanner;

/**
 *
 * @author lenovo
 */
public class calculator {
    //start of main() function....
    public static void main(String args[])
    {
        float a,b;
        //To enter two values....
        System.out.println("Enter Value of a:\n");
        Scanner obj=new Scanner(System.in);
        a=obj.nextFloat();
        System.out.println("Enter Value of b:\n");
        b=obj.nextFloat();
        int choice;
        System.out.println("Enter Your Choice :\n1. Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.ModularDivision");
        Scanner c=new Scanner(System.in);
        choice=c.nextInt();
        //Start of Switch....
        switch(choice)
        {
            
                case 1:
                    System.out.println("The Addition is = "+(a+b));
                    break;
                case 2:
                    System.out.println("The Subtraction is = "+(a-b));
                    break;
                case 3:
                    System.out.println("The Multiplication is = "+(a*b));
                    break;
                case 4:
                    System.out.println("The Division is = "+(a/b));
                    break;
                case 5:
                    System.out.println("The ModularDivision is = "+(a%b));
                    break;
        }//End of Switch
            
                
            
    }//End of main() function....
}



O/P:-



run:
Enter Value of a:

5
Enter Value of b:

3
Enter Your Choice :
1. Addition
2.Subtraction
3.Multiplication
4.Division
5.ModularDivision
4
The Division is = 1.6666666
BUILD SUCCESSFUL (total time: 5 seconds)
^