123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import java.util.*;
-
-
- public class Calculator {
-
-
- public static void main(String[] args) {
-
- double displayNum = 0;
- boolean calcOn = true;
- double num;
-
- Scanner sc = new Scanner(System.in);
-
- while (calcOn) {
-
- System.out.println(displayNum);
-
- System.out.println("Enter an option: ");
- System.out.println("0 - ENTER NUMBER");
- System.out.println("1 - ADD ");
- System.out.println("2 - SUBTRACT");
- System.out.println("3 - MULTIPLY");
- System.out.println("4 - DIVIDE");
- System.out.println("5 - SQUARE");
- System.out.println("6 - SQUARE ROOT");
- System.out.println("7 - EXPONENT");
- System.out.println("8 - Invert +/-");
- System.out.println("9 - INVERSE");
- System.out.println("10 - SIN");
- System.out.println("11 - COS");
- System.out.println("12 - TAN");
- System.out.println("13 - INVERSE SIN");
- System.out.println("14 - INVERSE COS");
- System.out.println("15 - INVERSE TAN");
- System.out.println("16 - QUIT");
-
-
-
-
- int userInput = sc.nextInt();
- //displayNum = userInput;
- System.out.println(displayNum);
-
- switch(userInput) {
- case 0: System.out.println("enter number");
- num = sc.nextDouble();
- displayNum = num;
- break;
- case 1: System.out.println("enter number to ADD to " + displayNum);
- num = sc.nextDouble();
- displayNum = num + displayNum;
- break;
- case 2: System.out.println("enter number to SUBTRACT from " + displayNum);
- num = sc.nextDouble();
- displayNum = displayNum - num;
- break;
- case 3: System.out.println("enter number to MULTIPLY to" + displayNum);
- num = sc.nextDouble();
- displayNum = num * displayNum;
- break;
- case 4: System.out.println("enter number to DIVIDE from " + displayNum);
- num = sc.nextDouble();
- displayNum = displayNum / num;
- break;
- case 5: System.out.println("square result: " + displayNum * displayNum);
- num = sc.nextDouble();
- // displayNum = displayNum * displayNum;
- break;
- case 6: System.out.println("square root result: " + Math.sqrt(displayNum));
- num = sc.nextDouble();
- break;
- case 7: System.out.println("enter an exponent to the number: " + displayNum);
- num = sc.nextDouble();
- displayNum = Math.pow(displayNum, num);
- break;
- case 8: System.out.println("result: " + displayNum * -1);
- num = sc.nextDouble();
- break;
- case 9: System.out.println("result: " + Math.sqrt(displayNum));
- num = sc.nextDouble();
- // displayNum = displayNum * displayNum;
- break;
- case 10: System.out.println("result: " + Math.sin(displayNum));
- num = sc.nextDouble();
- // displayNum = displayNum * displayNum;
- break;
- case 11: System.out.println("result: " + Math.cos(displayNum));
- num = sc.nextDouble();
- // displayNum = displayNum * displayNum;
- break;
- case 12: System.out.println("result: " + Math.tan(displayNum));
- num = sc.nextDouble();
- // displayNum = displayNum * displayNum;
- break;
- case 13: System.out.println("result: " + Math.asin(displayNum));
- num = sc.nextDouble();
- // displayNum = displayNum * displayNum;
- break;
- case 14: System.out.println("result: " + Math.acos(displayNum));
- num = sc.nextDouble();
- // displayNum = displayNum * displayNum;
- break;
- case 15: System.out.println("result: " + Math.atan(displayNum));
- num = sc.nextDouble();
- // displayNum = displayNum * displayNum;
- break;
- case 16: System.out.println("Quitting!");
- calcOn = false;
- break;
- default: break;
-
- }
-
- }
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
- }
|