Write a program in Java which will perform calculator functi

Write a program in Java which will perform calculator functions.

Solution

import java.util.Scanner;

public class JavaProgram

{

    public static void main(String args[])

    {

        float a, b, res;

        char choice, ch;

        Scanner scan = new Scanner(System.in);

                               

        do

        {

            System.out.print(\"1. Addition\ \");

            System.out.print(\"2. Subtraction\ \");

            System.out.print(\"3. Multiplication\ \");

            System.out.print(\"4. Division\ \");

            System.out.print(\"5. Exit\ \ \");

            System.out.print(\"Enter Your Choice : \");

            choice = scan.next().charAt(0);

            switch(choice)

            {

                case \'1\' : System.out.print(\"Enter Two Number : \");

                    a = scan.nextFloat();

                    b = scan.nextFloat();

                    res = a + b;

                    System.out.print(\"Result = \" + res);

                    break;

                case \'2\' : System.out.print(\"Enter Two Number : \");

                    a = scan.nextFloat();

                    b = scan.nextFloat();

                    res = a - b;

                    System.out.print(\"Result = \" + res);

                    break;

                case \'3\' : System.out.print(\"Enter Two Number : \");

                    a = scan.nextFloat();

                    b = scan.nextFloat();

                    res = a * b;

                    System.out.print(\"Result = \" + res);

                    break;

                case \'4\' : System.out.print(\"Enter Two Number : \");

                    a = scan.nextFloat();

                    b = scan.nextFloat();

                    res = a / b;

                    System.out.print(\"Result = \" + res);

                    break;

                case \'5\' : System.exit(0);

                    break;

                default : System.out.print(\"Wrong Choice!!!\");

                    break;

            }

            System.out.print(\"\ ---------------------------------------\ \");

        }while(choice != 5);      

    }

}

Write a program in Java which will perform calculator functions.Solutionimport java.util.Scanner; public class JavaProgram { public static void main(String args
Write a program in Java which will perform calculator functions.Solutionimport java.util.Scanner; public class JavaProgram { public static void main(String args

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site