Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 6th, 2018 69 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. //Tan, Benz Walter Jacques C.
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Tan_Switch
  6. {
  7.     public static void main(String args[])
  8.     {
  9.     Scanner sc = new Scanner(System.in);
  10.     System.out.println("\nCALCULATOR:\n");
  11.     System.out.print("Input 1st Number: ");
  12.     float input_1= sc.nextInt();
  13.     System.out.print("Input 2nd Number: ");
  14.     float input_2= sc.nextInt();
  15.     System.out.print("Input Operator(+,-,*,/): ");
  16.     float answer = 0;
  17.     char operator = sc.next().charAt(0);
  18.     boolean print = true;
  19.    
  20.         switch(operator)
  21.         {
  22.             case '+': answer = input_1 + input_2; break;
  23.            
  24.             case '-': answer = input_1 - input_2; break;
  25.            
  26.             case '*': answer = input_1 * input_2; break;
  27.            
  28.             case '/': answer = input_1 / input_2; break;
  29.            
  30.             default: System.out.println("Invalid Operation"); print = false; break;
  31.         }
  32.    
  33.         if(print==true)
  34.         {
  35.         System.out.println("The Answer of " + input_1 + " " + operator + " " + input_2 + " = " + answer);
  36.         }
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top