Guest User

Untitled

a guest
May 12th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1.  
  2. import java.util.*;
  3. public class Main {
  4.     public static void main(String args[]) {
  5.        Scanner sc = new Scanner(System.in);
  6. \
  7.         char ch = '+';
  8.         while(ch!='x'&&ch!='X'){
  9.             ch = sc.next().charAt(0);
  10.             switch(ch){
  11.                 case '+':{
  12.                    
  13.                     long n1 = sc.nextLong();
  14.                     long n2 = sc.nextLong();
  15.                     long res = n1+n2;
  16.                     System.out.println(res);
  17.                     break;
  18.                 }
  19.                 case '-':{
  20.                     long n1 = sc.nextLong();
  21.                     long n2 = sc.nextLong();
  22.                     long res = n1-n2;
  23.                     System.out.println(res);
  24.                     break;
  25.                 }
  26.                 case '*':{
  27.                     long n1 = sc.nextLong();
  28.                     long n2 = sc.nextLong();
  29.                     long res = n1*n2;
  30.                     System.out.println(res);
  31.                     break;
  32.                 }
  33.                 case '/':{
  34.                     long n1 = sc.nextLong();
  35.                     long n2 = sc.nextLong();
  36.                     long res = n1/n2;
  37.                     System.out.println(res);
  38.                     break;
  39.                 }
  40.                 case '%':{
  41.                     long n1 = sc.nextLong();
  42.                     long n2 = sc.nextLong();
  43.                     long res = n1%n2;
  44.                     System.out.println(res);
  45.                     break;
  46.                 }
  47.                 case 'x': case 'X' :{
  48.                     sc.close();
  49.                     break;
  50.                 }
  51.                 default:{
  52.                     System.out.println("Invalid operation. Try again.");
  53.                     break;
  54.                 }
  55.             }
  56.         }
  57.  
  58.     }
  59. }
Add Comment
Please, Sign In to add comment