Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Main {
  4.   public static void main(String[] args) {
  5.     Scanner inp = new Scanner(System.in);
  6.     System.out.print("In:");
  7.     String exp = inp.nextLine();
  8.     //write your code below:
  9.    
  10.     //Addition
  11.     if(exp.contains("+")) {
  12.       int operationLocation = exp.indexOf("+");
  13.       int num1 = Integer.parseInt(exp.substring(0, operationLocation));
  14.       int num2 = Integer.parseInt(exp.substring(operationLocation + 1));
  15.       int result = num1 + num2;
  16.      
  17.       System.out.println(result);
  18.      
  19.     }
  20.    
  21.     //Subtraction
  22.     if(exp.contains("-")) {
  23.       int operationLocation = exp.indexOf("-");
  24.       int num1 = Integer.parseInt(exp.substring(0, operationLocation));
  25.       int num2 = Integer.parseInt(exp.substring(operationLocation + 1));
  26.       int result = num1 - num2;
  27.      
  28.       System.out.println(result);
  29.      
  30.     }
  31.    
  32.     //Multiplcation
  33.     if(exp.contains("*")) {
  34.       int operationLocation = exp.indexOf("*");
  35.       int num1 = Integer.parseInt(exp.substring(0, operationLocation));
  36.       int num2 = Integer.parseInt(exp.substring(operationLocation + 1));
  37.       int result = num1 * num2;
  38.      
  39.       System.out.println(result);
  40.      
  41.     }
  42.    
  43.     //Modulo
  44.     if(exp.contains("%")) {
  45.       int operationLocation = exp.indexOf("%");
  46.       int num1 = Integer.parseInt(exp.substring(0, operationLocation));
  47.       int num2 = Integer.parseInt(exp.substring(operationLocation + 1));
  48.       int result = num1 % num2;
  49.      
  50.       System.out.println(result);
  51.      
  52.     }
  53.    
  54.     //Division
  55.     if(exp.contains("/")) {
  56.       int operationLocation = exp.indexOf("/");
  57.       int num1 = Integer.parseInt(exp.substring(0, operationLocation));
  58.       int num2 = Integer.parseInt(exp.substring(operationLocation + 1));
  59.       int result = num1 / num2;
  60.      
  61.       System.out.println(result);
  62.      
  63.     }
  64.  
  65.  
  66.  
  67.  
  68.    
  69.   }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement