Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MathematicOperations {
  4. private static Scanner in;
  5.  
  6. public static void Sum() {
  7. in = new Scanner(System.in);
  8. System.out.print("Enter the first No :");
  9. int x = in.nextInt();
  10. System.out.print("Enter the secound No :");
  11. int y = in.nextInt();
  12. int result = x + y;
  13. System.out.println(result);
  14. in.close();
  15. }
  16.  
  17. public static void Sub() {
  18. in = new Scanner(System.in);
  19. System.out.print("Enter the first No :");
  20. int x = in.nextInt();
  21. System.out.print("Enter the secound No :");
  22. int y = in.nextInt();
  23. int result = x - y;
  24. System.out.println(result);
  25. in.close();
  26. }
  27.  
  28. public static void Mul() {
  29. in = new Scanner(System.in);
  30. System.out.print("Enter the first No :");
  31. int x = in.nextInt();
  32. System.out.print("Enter the secound No :");
  33. int y = in.nextInt();
  34. int result = x * y;
  35. System.out.println(result);
  36. in.close();
  37. }
  38.  
  39. public static void Div() {
  40. in = new Scanner(System.in);
  41. System.out.print("Enter the first No :");
  42. int x = in.nextInt();
  43. System.out.print("Enter the secound No :");
  44. int y = in.nextInt();
  45. if (y == 0)
  46. System.out.println("Cannot dived by zero");
  47. else {
  48. int result = x / y;
  49. System.out.println(result);
  50. in.close();
  51. }
  52. }
  53. }
  54.  
  55. import java.util.Scanner;
  56.  
  57. public class SelectOperation {
  58. private static Scanner scn;
  59. private static int num;
  60.  
  61. public SelectOperation() {
  62. scn = new Scanner(System.in);
  63. System.out.print("1.Sum : , 2.Sub : , 3.Mul : , 4.Div :");
  64. num = scn.nextInt();
  65.  
  66. switch (num) {
  67. case 1:
  68. MathematicOperations.Sum();
  69. break;
  70. case 2:
  71. MathematicOperations.Sub();
  72. break;
  73. case 3:
  74. MathematicOperations.Mul();
  75. break;
  76. case 4:
  77. MathematicOperations.Div();
  78. break;
  79. default:
  80. System.out.println("Invalid Operation");
  81. break;
  82. }
  83. scn.close();
  84. }
  85. }
  86.  
  87. public class Main {
  88.  
  89. public static void main(String[] args) {
  90. new SelectOperation();
  91.  
  92. }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement