fork download
  1. import java.util.Scanner;
  2. class Jtutorial1 {
  3. public static void main(String args[]){
  4. Scanner input = new Scanner(System.in);
  5. int x=0, y=0, select=0;
  6. System.out.println("Enter number 1: ");
  7. x=input.nextInt();
  8. System.out.println("Enter number 2: ");
  9. y=input.nextInt();
  10.  
  11. System.out.println("Press 1 for addition, 2 for subtraction, 3 for multiplication, 4 for division. ");
  12. select=input.nextInt();
  13.  
  14. switch(select){ //switch(2) -- case 2
  15. case 1:{
  16. System.out.println("X + Y = " + (x+y));
  17. break;
  18. }
  19. case 2:{
  20. System.out.println("X - Y = " + (x-y));
  21. break;
  22. }
  23. case 3:{
  24. System.out.println("X * Y = " + (x*y));
  25. break;
  26. }
  27. case 4:{
  28. System.out.println("X / Y = " + (x/y));
  29. break;
  30. }
  31. default:{
  32. System.out.println("Something went horribly wrong");
  33. break;
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. }
  42.  
  43.  
  44. }//end main
  45. }//end class
Success #stdin #stdout 0.07s 213888KB
stdin
12
6
1
stdout
Enter number 1: 
Enter number 2: 
Press 1 for addition, 2 for subtraction, 3 for multiplication, 4 for division. 
X + Y = 18