瀏覽代碼

added error message for inverse of 0

Lauren Green 6 年之前
父節點
當前提交
80fc55d1bb
共有 1 個文件被更改,包括 8 次插入4 次删除
  1. 8
    4
      Console.java

+ 8
- 4
Console.java 查看文件

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