Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3. public class Main {
  4. public static void main(String[] args) {
  5. public class Calc {
  6. static Scanner scanner = new Scanner(System.in);
  7. public static void main(String[] args) {
  8. int a = getInt();
  9. int b = getInt();
  10. char operation = getOperation();
  11. int result = calc(a, b ,operation);
  12. System.out.println(result);
  13. }
  14.  
  15. public static int getInt(){
  16. int num;
  17. if(scanner.NextInt()){
  18. num = scanner.nextInt();
  19. }
  20. return num;
  21. }
  22.  
  23. public static char getOperation(){
  24. char operation = 0;
  25. if(scanner.hasNext()){
  26. operation = scanner.next().charAt(0);
  27. }
  28. return operation;
  29. }
  30.  
  31. public static int calc(int a, int b, char operation){
  32. int result;
  33. switch (operation){
  34. case '+':
  35. result = a + b;
  36. break;
  37. case '-':
  38. result = a - b ;
  39. break;
  40. case '*':
  41. result = a * b ;
  42. break;
  43. case '/':
  44. result = a/b;
  45. break;
  46. }
  47. return result;
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement