From 892919992c721144cc793637b07e4448f36e03af Mon Sep 17 00:00:00 2001 From: gulatikeshav <133638164+gulatikeshav@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:56:43 +0530 Subject: [PATCH] Create calculator.java --- calculator.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 calculator.java diff --git a/calculator.java b/calculator.java new file mode 100644 index 00000000000..d67b10b4a32 --- /dev/null +++ b/calculator.java @@ -0,0 +1,34 @@ +import java.util.*; + +public class calculator{ + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + + System.out.println("Enter a : "); + int a = sc.nextInt(); + System.out.println("Enter b : "); + int b = sc.nextInt(); + System.out.println("Enter operator : "); + + char operator = sc.next().charAt(0); + + + switch(operator){ + + case '+' : System.out.println(a+b); + break; + case '-' : System.out.println(a-b); + break; + case '/' : System.out.println(a/b); + break; + case '*' : System.out.println(a*b); + break; + case '%' : System.out.println(a%b); + break; + default : System.out.println("wrong operator"); + + } + sc.close(); + + } +}