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){
  11. int answer;
  12. Scanner scan = new Scanner(System.in);
  13. String input;
  14. System.out.println("Enter your operation please");
  15. input = scan.nextLine();
  16. if(input.charAt(findsign(input))=='+'){
  17. answer = firstnumber(input)+secondnumber(input);
  18. System.out.println("Operation is addition");
  19. System.out.println("The answer is " + answer);
  20. }
  21. else if(input.charAt(findsign(input))=='-'){
  22. answer = firstnumber(input)-secondnumber(input);
  23. System.out.println("Operation is subtraction");
  24. System.out.println("The answer is " + answer);
  25. }
  26. else if(input.charAt(findsign(input))=='*'){
  27. answer = firstnumber(input)*secondnumber(input);
  28. System.out.println("Operation is multiplication");
  29. System.out.println("The answer is " + answer);
  30. }
  31. else if(input.charAt(findsign(input))=='/'){
  32. answer = firstnumber(input)/secondnumber(input);
  33. System.out.println("Operation is division");
  34. System.out.println("The answer is " + answer);
  35. }
  36.  
  37. }
  38.  
  39. public static int findsign(String input){
  40. int n=0;
  41. for (n=0;n<input.length();n++){
  42. if(input.charAt(n)=='+' || input.charAt(n)=='-' || input.charAt(n)=='*' || input.charAt(n)=='/'){
  43. break;
  44. }
  45. }
  46. return n;
  47. }
  48. public static int firstnumber(String input){
  49.  
  50. String number1 = input.substring(0,findsign(input));
  51. int number = Integer.parseInt(number1);
  52. return number;
  53. }
  54. public static int secondnumber(String input){
  55. String number2 = input.substring(findsign(input)+1,input.length());
  56. int number = Integer.parseInt(number2);
  57. return number;
  58. }
  59.  
  60. }
Success #stdin #stdout 0.13s 321344KB
stdin
13*4
stdout
Enter your operation please
Operation is multiplication
The answer is 52