From 13f53045b86add0ca451ca5e28cbf3213a078fe2 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Sat, 15 Oct 2022 11:52:17 +0530 Subject: [PATCH] basic calculator made from java --- .../Patterns/calculator.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 0_JavaProgrammingBasics/Patterns/calculator.java diff --git a/0_JavaProgrammingBasics/Patterns/calculator.java b/0_JavaProgrammingBasics/Patterns/calculator.java new file mode 100644 index 0000000..d3cc969 --- /dev/null +++ b/0_JavaProgrammingBasics/Patterns/calculator.java @@ -0,0 +1,26 @@ +import java.util.*; +public class calculator { + public static void main(String[] args) { + try (Scanner sc = new Scanner(System.in)) { + System.out.print("enter a -->"); + int a = sc.nextInt(); + System.out.print("enter b -->"); + int b = sc.nextInt(); + System.out.print("what calculation you want -->"); + 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("not to be calculated"); + } + } + } +}