diff --git a/Calculator.java b/Calculator.java new file mode 100644 index 0000000..e347fc6 --- /dev/null +++ b/Calculator.java @@ -0,0 +1,73 @@ +import java.util.Scanner; + +public class Calculator { + + public static void main(String[] args) { + + Scanner input = new Scanner(System.in); + + int ans = 0; + + while (true) { + + System.out.print("Enter a operator [+ - * / %] = "); + + char op = input.next().trim().charAt(0); + + if (op == '+' || op == '-' || op == '*' || op == '/' || op == '%') { + + System.out.print("Enter one numbers : "); + + int num1 = input.nextInt(); + + System.out.print("Enter two numbers : "); + + int num2 = input.nextInt(); + + if (op == '+') { + + ans = num1 + num2; + + } + + if (op == '-') { + + ans = num1 - num2; + + } + + if (op == '*') { + + ans = num1 * num2; + + } + + if (op == '/') { + + if (num2 != 0) { + + ans = num1 / num2; + + } + + } + + if (op == '%') { + + ans = num1 % num2; + + } + + } else if (op == 'x' || op == 'X') { + + break; + + } + + System.out.println("Result = " + ans); + + } + + } + +}