Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.*;
- class calc{
- int result, operator1, operator2;
- char operand;
- int add(int a, int b){
- return a+b;
- }
- int sub(int a, int b){
- return a-b;
- }
- public void calc(){
- Scanner in = new Scanner(System.in);
- System.out.println("\nEnter first operator: ");
- operator1 = in.nextInt();
- System.out.println("\nEnter second operator: ");
- operator2 = in.nextInt();
- System.out.println("\nEnter operand(options-> + - * /): ");
- operator2 = in.next().charAt(0);
- System.out.println("\nCalculating.....");
- switch(operand){
- case '+':
- result = add(operator1, operator2);
- System.out.println("\nResult:"+result);
- case '-':
- result = sub(operator1, operator2);
- System.out.println("\nResult:"+result);
- default:
- System.out.println("\nWrong choice of operand!");
- }
- }
- }
- class test{
- public static void main(String args[]){
- calc c1 = new calc();
- }
- }
Add Comment
Please, Sign In to add comment