0
我有這樣的代碼,需要用戶輸入的號碼,並把它變成最終的方程式。但是,編譯時我總是收到錯誤/異常; 「錯誤:變量convertToNumL可能尚未初始化。」我明白錯誤在說什麼,但是,我不知道如何調試。進行輸入讀取整數轉換,並進行合計代入方程
這是我所知,try/catch塊以某種方式防止了可變convertToNum(其從.readLine()方法獲得)。任何人都可以告訴我如何解決這個問題?
非常感謝。我的代碼
部分:
if (realNumber2)
{
//Question 4: Height
while (realNumber2 = true) {
System.out.println ("3) Please enter the height of the triangle face.");
try
{
stringTriangleHeight = myInput.readLine();
convertToNumH = Double.parseDouble (stringTriangleHeight);
Integer.parseInt (stringTriangleHeight);
System.out.println ("Your triangle height is " + stringTriangleHeight + " " + Units + ".");
realNumber3 = true;
break;
}
catch (Exception e)
{
System.out.println ("That was either a smart remark, a negative number or jibberish.");
realNumber3 = true;
}
}
while (realNumber3) {
total1 = convertToNumL * convertToNumW; //base area, length x width
total2 = convertToNumL * convertToNumH/2; //triangle area using sidelength 'length', base x height/2
total3 = convertToNumW * convertToNumH/2; //triangle area using sidelength 'width , base x height/2