From e97cdb2be169f89d4a8d970b1b692f2a7cd80f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D8=A7=D8=AD=D9=85=D8=AF=20=D8=A7=D8=A8=D9=88=20=D8=AD?= =?UTF-8?q?=D8=B3=D9=86?= <36786100+eby8zevin@users.noreply.github.com> Date: Thu, 28 Oct 2021 22:02:38 +0700 Subject: [PATCH] Create Calculator.java --- Calculator.java | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Calculator.java 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); + + } + + } + +}