Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Tan, Benz Walter Jacques C.
- import java.util.Scanner;
- public class Tan_Switch
- {
- public static void main(String args[])
- {
- Scanner sc = new Scanner(System.in);
- System.out.println("\nCALCULATOR:\n");
- System.out.print("Input 1st Number: ");
- float input_1= sc.nextInt();
- System.out.print("Input 2nd Number: ");
- float input_2= sc.nextInt();
- System.out.print("Input Operator(+,-,*,/): ");
- float answer = 0;
- char operator = sc.next().charAt(0);
- boolean print = true;
- switch(operator)
- {
- case '+': answer = input_1 + input_2; break;
- case '-': answer = input_1 - input_2; break;
- case '*': answer = input_1 * input_2; break;
- case '/': answer = input_1 / input_2; break;
- default: System.out.println("Invalid Operation"); print = false; break;
- }
- if(print==true)
- {
- System.out.println("The Answer of " + input_1 + " " + operator + " " + input_2 + " = " + answer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement