Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class calc {
- public static void main(String args[])
- {
- Scanner sc = new Scanner(System.in);
- boolean flag = true;
- while(flag)
- {
- System.out.print("\nEnter 1st no : ");
- float a = sc.nextFloat();
- System.out.print("Enter 2nd no : ");
- float b = sc.nextFloat();
- System.out.print("Enter operator(+, -, *, /, %) : ");
- char op = sc.next().charAt(0);
- switch(op)
- {
- case '+' :
- System.out.println("\n" + a + " + " + b + " = " + (a+b) );
- break;
- case '-' :
- System.out.println("\n" + a + " - " + b + " = " + (a-b) );
- break;
- case '/' :
- System.out.println("\n" + a + " / " + b + " = " + (a/b) );
- break;
- case '*' :
- System.out.println("\n" + a + " * " + b + " = " + (a*b) );
- break;
- case '%' :
- System.out.println("\n" + a + " % " + b + " = " + (a%b) );
- break;
- default:
- System.out.println("Invalid operator!");
- }
- System.out.print("Continue(y/n) : ");
- char ans = sc.next().charAt(0);
- if(ans == 'n')
- flag = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement