fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int result = 0;
  13.  
  14. Scanner sc = new Scanner(System.in);
  15. System.out.println("Enter number");
  16. int number = sc.nextInt();
  17. System.out.println("Enter operation");
  18. System.out.println("1.+");
  19. System.out.println("2.-");
  20. System.out.println("3.*");
  21. System.out.println("4./");
  22. System.out.println("5.=");
  23. int operation = sc.nextInt();
  24. try{
  25. while (operation != 5) {
  26.  
  27.  
  28. switch (operation) {
  29. case 1:
  30. result += number;
  31. System.out.println("result= " + result);
  32. break;
  33. case 2:
  34. result -= number;
  35. System.out.println("result= " + result);
  36. break;
  37. case 3:
  38. result *= number;
  39. System.out.println("result= " + result);
  40. break;
  41. case 4:
  42. result /= number;
  43. System.out.println("result= " + result);
  44. break;
  45.  
  46. }
  47.  
  48. System.out.println("Enter next number");
  49. number = sc.nextInt();
  50. System.out.println("Enter operation");
  51. operation = sc.nextInt();
  52.  
  53.  
  54. }
  55. System.out.println("Final result is "+result);
  56. }catch(Exception e){
  57. System.out.println(e);
  58. }
  59. }
  60. }
Success #stdin #stdout 0.14s 321088KB
stdin
2 1 5 5
stdout
Enter number
Enter operation
1.+
2.-
3.*
4./
5.=
result= 2
Enter next number
Enter operation
Final result is 2