Przeglądaj źródła

added error message for inverse of 0

Lauren Green 6 lat temu
rodzic
commit
80fc55d1bb
1 zmienionych plików z 8 dodań i 4 usunięć
  1. 8
    4
      Console.java

+ 8
- 4
Console.java Wyświetl plik

@@ -73,10 +73,11 @@ public class Console {
73 73
                     basicAnswer = Double.NaN;
74 74
                     Console.println("Invalid Input");
75 75
                 }
76
-                
76
+
77 77
                 Console.println(Double.toString(basicAnswer));
78
-            
78
+
79 79
                 break;
80
+
80 81
                 case "2":
81 82
                 advCalc.realAdvanced();
82 83
                 String mode = Console.getStringInput("Enter the mode: ");
@@ -94,9 +95,12 @@ public class Console {
94 95
                     advAnswer = advCalc.exponent(advInput1,advInput2);
95 96
 
96 97
                 }else if (mode.equals("3")){
97
-
98
+                    if (advInput1 == 0) {
99
+                        Console.println("undefined");
100
+                        advAnswer = Double.NaN;
101
+                    } else {
98 102
                     advAnswer = advCalc.inverse(advInput1);
99
-
103
+                }
100 104
                 }else if (mode.equals("4")){
101 105
                     advAnswer = advCalc.opposite(advInput1);
102 106