Share all news to all guy ;)

Monday, December 22, 2014


               Write a program that will display the calculator menu. The program will prompt the user to choose the operation choice (from 1 to 5). Then it asks the user to input two integer vales for the calculation. See the sample below.

Code Here :

 public static void main(String[] args) {
        int Num1, Num2, op, Result = 0;
        char ch;
        do {
            Scanner In = new Scanner(System.in);
            System.out.println("MAIN MENU");
            System.out.println("1.Add");
            System.out.println("2.Subtract");
            System.out.println("3.Multipy");
            System.out.println("4.Divide");
            System.out.println("5.Mudulus");
            System.out.println(" ");
            System.out.print("Enter Yours Choice: ");
            op = In.nextInt();
            System.out.print("Enter Your Two Number: ");
            Num1 = In.nextInt();
            Num2 = In.nextInt();
            switch (op) {
                case 1:
                    Result = Num1 + Num2;
                    break;
                case 2:
                    Result = Num1 - Num2;
                    break;
                case 3:
                    Result = Num1 * Num2;
                    break;
                case 4:
                    Result = Num1 / Num2;
                    break;
                case 5:
                    Result = Num1 % Num2;
                    break;
                default:
                    System.out.println("You're Enter in Wrong Operator");
            }
            System.out.println("Your Result is: " + Result);
            System.out.println(" ");
            System.out.print("Do you want to calculate agian ? : [Y/N] ");
            ch = In.next().charAt(0);
        }while(ch=='y' || ch=='Y');
        
    }
}

Before You Go : Help Like my Facebook Page :  www.facebook.com/Str168 or on my Web Page . And Help Subscribe my Youtube Channel : https://www.youtube.com/channel/UC79-6IEtqwIwGvDXZCQE-4A/feed?view_as=public For get the news Videos of Key Of IT . Thank You ;)

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.