Write an application that prompts the user for two integers

Write an application that prompts the user for two integers and then prompts the user to enter an option as follows: 1 to add the two integers, 2 to subtract the second integer from the first, 3 to multiply the integers and 4 to divide the first integer by the second. Display the results of the arithmetic

Solution

import java.util.Scanner;
public class arithmetic {
public static void main(String[] args) {
      
       System.out.println(\"Enter Two integers \");
       System.out.println(\"Enter 1st Integer: \");
       Scanner scan = new Scanner(System.in);
       int a = scan.nextInt();
       System.out.println(\"Enter 2nd Integer: \");
       int b = scan.nextInt();
       System.out.println(\"\ 1 to add the two integers\ 2 to subtract the second integer from the first\ 3 to multiply the integers\ 4 to divide the first integer by the second\ 5.Exit\");
       int option=scan.nextInt();
       switch(option){
               case 1:
               System.out.println(\"Addition of \"+\" \"+a+\" and \"+b+\" is \"+(a+b));
               break;  
               case 2:
               System.out.println(\"Addition of \"+\" \"+a+\" and \"+b+\" is \"+(b-a));
               break;
               case 3:
               System.out.println(\"Addition of \"+\" \"+a+\" and \"+b+\" is \"+(a*b));
               break;
               case 4:
               System.out.println(\"Addition of \"+\" \"+a+\" and \"+b+\" is \"+(a/b));
               case 5:
               System.exit(0);
               break;
               default:
               System.out.println(\"Enter correct option\");  
       }
   }
}

Write an application that prompts the user for two integers and then prompts the user to enter an option as follows: 1 to add the two integers, 2 to subtract th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site