Advertisement
sahcacrepnite

calculator

Feb 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.02 KB | None | 0 0
  1. import java.util.*;
  2. public class MyProgram
  3. {
  4.     public static void main(String... args)
  5.     {
  6.         //setting up variables
  7.         boolean bRestart = false;
  8.         double starting = 1;
  9.         double num1;
  10.         double num2;
  11.         double output;
  12.         int operator = 0;
  13.         Scanner input = new Scanner(System.in);
  14.         //the whole loop
  15.         System.out.println("henlo!");
  16.         while (starting > 0)
  17.         {
  18.             //initialization
  19.             System.out.println("num 1 pls");
  20.             num1 = input.nextDouble();
  21.            
  22.             System.out.println("thanks. 2nd number also");
  23.             num2 = input.nextDouble();
  24.            
  25.             System.out.println("ok cool. now the operation.");
  26.             System.out.println("1 for addition,");
  27.             System.out.println("2 for subtraction, ");
  28.             System.out.println("3 for multiplication, ");
  29.             System.out.println("and 4 for division.");
  30.             operator = input.nextInt();
  31.             System.out.println(operator);
  32.             System.out.println("alrighty");
  33.             //mathematical times
  34.             if (operator == 1)
  35.             {
  36.                 output = (num1+num2);
  37.                 for (int i = 0; i < 15; i++)
  38.                 {
  39.                     System.out.println();
  40.                 }
  41.                 System.out.println(num1);
  42.                 System.out.println("+");
  43.                 System.out.println(num2);
  44.                 System.out.println("=");
  45.                 System.out.println(output);
  46.                 System.out.println( );
  47.                
  48.             }
  49.             if (operator == 2)
  50.             {
  51.                 output = (num1-num2);
  52.                 for (int i = 0; i < 15; i++)
  53.                 {
  54.                     System.out.println();
  55.                 }
  56.                 System.out.println(num1);
  57.                 System.out.println("-");
  58.                 System.out.println(num2);
  59.                 System.out.println("=");
  60.                 System.out.println(output);
  61.                 System.out.println( );
  62.                 System.out.println( );
  63.                 System.out.println( );
  64.             }
  65.             else if (operator == 3)
  66.             {
  67.                 output = (num1*num2);
  68.                 for (int i = 0; i < 15; i++)
  69.                 {
  70.                     System.out.println();
  71.                 }
  72.                 System.out.println(num1);
  73.                 System.out.println("*");
  74.                 System.out.println(num2);
  75.                 System.out.println("=");
  76.                 System.out.println(output);
  77.                 System.out.println( );
  78.             }
  79.             else if (operator == 4)
  80.             {
  81.                 if (num2 != 0)
  82.                 {
  83.                     output = (num1/num2);
  84.                     for (int i = 0; i < 15; i++)
  85.                     {
  86.                         System.out.println();
  87.                     }
  88.                     System.out.println(num1);
  89.                     System.out.println("/");
  90.                     System.out.println(num2);
  91.                     System.out.println("=");
  92.                     System.out.println(output);
  93.                     System.out.println( );
  94.                 }
  95.                 else
  96.                 {
  97.                     for (int i = 0; i < 15; i++)
  98.                     {
  99.                         System.out.println();
  100.                     }
  101.                     System.out.println("wait a second");
  102.                     System.out.println("dude what the hecc");
  103.                     System.out.println("don't divide by zero");
  104.                 }
  105.  
  106.             }
  107.             //redo machine
  108.             System.out.println("oki doki");
  109.             System.out.println("wanna go again? true/false");
  110.             bRestart = input.nextBoolean();
  111.             if (!bRestart)
  112.             {
  113.                 starting = 0;
  114.             }
  115.             else if (bRestart)
  116.             {
  117.                 starting++;
  118.                 System.out.println("k here we go");
  119.             }
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement