3) Write a program using switch and break separately to print the desired output when you give an input as 1 to add, 2 to multiply, 3 to subtract.
import java.util.Scanner;
public class Question1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Write to numbers");
int x1 = in.nextInt();
int x2 = in.nextInt();
int result = 0;
System.out.println("Write number of action");
int action = in.nextInt();
switch(action){
case 1:
result = x1+x2;
break;
case 2:
result = x1*x2;
break;
case 3:
result = x1-x2;
break;
}
System.out.println(result);
}
}