Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myPkg;
- import java.util.Scanner;
- public class Ex03 {
- public static void main(String[] args) {
- int x, y;
- char op;
- Scanner in = new Scanner(System.in);
- System.out.println("Enter two numbers: ");
- x = in.nextInt();
- y = in.nextInt();
- System.out.println("Enter an operation ( +, -, *, /): ");
- op = in.next().charAt(0);
- double res;
- if (op == '+')
- res = x + y;
- else if (op == '-')
- res = x - y;
- else if (op == '*')
- res = x * y;
- else
- {
- if (y==0)
- System.out.println("Error!");
- res = 1.0*x / y;
- }
- System.out.println("" + x + op + y + "=" + res);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement