Calculator - Coder's point

Saturday, June 1, 2019

Calculator

 
public class Calculator { static void main() { java.util.Scanner in = new java.util.Scanner(System.in); System.out.println("Enter 2 nos."); double a=in.nextInt(); double b=in.nextInt(); System.out.println("Enter operator + or - or * or /"); char ch=in.next().charAt(0); System.out.println("Result:"); switch(ch) { case '+': System.out.println(a+b); break; case '-': System.out.println(a-b); break; case '*': System.out.println(a*b); break; case '/': if(b==0)System.out.println("Cannot divide by Zero"); else System.out.println(a/b); break; default: System.out.println("Wrong choice"); } } }
OUTPUT:
Enter 2 nos.
10
21
Enter operator + or - or * or /
+
Result:
31.0
Enter 2 nos.
34
56
Enter operator + or - or * or /
*
Result:
1904.0

No comments:

Post a Comment