fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8.  
  9. import java.util.Scanner;
  10.  
  11. public class Main {
  12.  
  13. public static Scanner s = new Scanner(System.in); //<-- DO NOT TOUCH
  14.  
  15. public static void main(String[] args) {
  16. String oper = s.next();
  17. int numberOne = s.nextInt(); //Enter your first number
  18. int numberTwo = s.nextInt(); //Enter your second number
  19. int total = calcu(oper, numberOne, numberTwo); //Perform calculation
  20. System.out.println(total); //Print the total
  21. }
  22.  
  23. static int calcu(String oper, int numberOne, int numberTwo) {
  24.  
  25. if (oper.equals("+")) {
  26. int total = add(numberOne, numberTwo);
  27. return total;
  28. } else if (oper.equals("-")) {
  29. int total = sub(numberOne, numberTwo);
  30. return total;
  31. } else if (oper.equals("*")) {
  32. int total = multi(numberOne, numberTwo);
  33. return total;
  34. } else if (oper.equals("/")) {
  35. int total = div(numberOne, numberTwo);
  36. return total;
  37. }
  38. System.out.println("Invalid Operator...");
  39. return -1;
  40. }
  41.  
  42. static int add(int numberOne, int numberTwo) {
  43. return numberOne + numberTwo;
  44.  
  45.  
  46. }
  47.  
  48. static int multi(int numberOne, int numberTwo) {
  49. return numberOne * numberTwo;
  50.  
  51. }
  52.  
  53. static int sub(int numberOne, int numberTwo) {
  54. return numberOne - numberTwo;
  55.  
  56. }
  57.  
  58. static int div(int numberOne, int numberTwo) {
  59. return numberOne / numberTwo;
  60. }
  61.  
  62.  
  63. }
Success #stdin #stdout 0.1s 380672KB
stdin
-  5 5
stdout
0