Advertisement
mmayoub

School11, 170910, Ex03

Sep 10th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. package myPkg;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex03 {
  6.  
  7.     public static void main(String[] args) {
  8.         int x, y;
  9.         char op;
  10.  
  11.         Scanner in = new Scanner(System.in);
  12.         System.out.println("Enter two numbers: ");
  13.         x = in.nextInt();
  14.         y = in.nextInt();
  15.  
  16.         System.out.println("Enter an operation ( +, -, *, /): ");
  17.         op = in.next().charAt(0);
  18.         double res;
  19.         if (op == '+')
  20.             res = x + y;
  21.         else if (op == '-')
  22.             res = x - y;
  23.         else if (op == '*')
  24.             res = x * y;
  25.         else
  26.         {
  27.             if (y==0)
  28.             System.out.println("Error!");
  29.             res = 1.0*x / y;
  30.         }
  31.         System.out.println("" + x + op + y + "=" + res);
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement