SHARE
TWEET

Untitled

a guest Sep 22nd, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2.  
  3. public class JavaCalc
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         int number1;
  8.         int number2;
  9.         String whatToCalcBy;
  10.         int result;
  11.        
  12.         String tempNumber;
  13.  
  14.         try {
  15.        
  16.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  17.  
  18.         System.out.print("What is the first number? ");
  19.        
  20.         tempNumber = reader.readLine();
  21.        
  22.         number1 = Integer.parseInt(tempNumber);
  23.        
  24.         tempNumber = "";
  25.  
  26.         System.out.print("\nWhat is the second number? ");
  27.        
  28.         tempNumber = reader.readLine();
  29.        
  30.         number2 = Integer.parseInt(tempNumber);
  31.        
  32.         System.out.print("\nWhat would you like to calculate by? ");
  33.        
  34.         whatToCalcBy = reader.readLine();
  35.        
  36.         System.out.println(whatToCalcBy);
  37.        
  38.         if (whatToCalcBy == "+")
  39.         {
  40.             result = number1 + number2;
  41.         }
  42.         if (whatToCalcBy == "-")
  43.         {
  44.             result = number1 - number2;
  45.         }
  46.         if (whatToCalcBy == "/")
  47.         {
  48.             result = number1 / number2;
  49.         }
  50.         if (whatToCalcBy == "*")
  51.         {
  52.             result = number1 * number2;
  53.         }
  54.         else
  55.         {
  56.             result = number1 + number2;
  57.         }
  58.  
  59.        
  60.         System.out.println("\nYour result is: " + result);
  61.        
  62.         }
  63.         catch(Exception ex)
  64.         {
  65.             System.err.println("Error, soemthing went wrong!");
  66.         }
  67.        
  68.     }
  69.  
  70. }
RAW Paste Data
Top