Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- => Make Calculator in Java.
- --------------------------------------------------
- import java.util.Scanner;
- public class Calculator {
- public static void main(String[] args) {
- int a,b, res;
- char choice, ch;
- Scanner sc=new Scanner(System.in);
- System.out.println("Here are our option");
- System.out.println("1. Addition");
- System.out.println("2. Subtraction");
- System.out.println("3. Division");
- System.out.println("4. Multiplication");
- System.out.println("Enter your choice");
- choice=sc.next().charAt(0);
- switch(choice)
- {
- case '1': System.out.println("Enter any two number");
- a=sc.nextInt();
- b=sc.nextInt();
- res=a+b;
- System.out.println("Your Result is="+" "+res);
- break;
- case '2': System.out.println("Enter any two number");
- a=sc.nextInt();
- b=sc.nextInt();
- res=a-b;
- System.out.println("Your Result is="+" "+res);
- break;
- case '3': System.out.println("Enter any two number");
- a=sc.nextInt();
- b=sc.nextInt();
- res=a/b;
- System.out.println("Your Result is="+" "+res);
- break;
- case '4': System.out.println("Enter any two number");
- a=sc.nextInt();
- b=sc.nextInt();
- res=a*b;
- System.out.println("Your Result is="+" "+res);
- break;
- }
- System.out.println("------------------------------------------");
- }
- }
- -----------------------------------------------------------------------------------
- When the above Java Program is compile and executed, it will produce the following output:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement