-2

私はJavaにかなり慣れていないので、入力と温度を比較しようとするたびに、入力と温度が同じでなくても、すべての結果が配列に表示されます。

コード:

if (jRadioButton1.isSelected()) 
{ 
    String temp; 
    try
    {
        for (int i = 0; i < 500; i++)
        { 
            temp = Integer.toString(Read.tempHigh[i]);

            if ( input.equals(temp) );
            {   
                j.TextArea3.append(temp);
                j.TextArea3.append(input);
            }
        }
    }
    catch (NumberFormatException e)
    {   
        jTextArea3.append("Please enter a number");
    }
}
4

1 に答える 1

6

あなたのライン...

if ( input.equals(temp) );

;末尾に を付けないでください。シンボルは if ステートメントを閉じているため、との値に関係なく;、常に行が実行されます。j.TextArea3.append()inputtemp

したがって、上記のコードは次のようになります...

if (jRadioButton1.isSelected()){ 
    String temp; 
    try {
        for (int i = 0; i < 500; i++){ 
            temp = Integer.toString(Read.tempHigh[i]);

            if ( input.equals(temp) ) {   
                j.TextArea3.append(temp);
                j.TextArea3.append(input)
            }
        }
    }
    catch (NumberFormatException e){   
        jTextArea3.append("Please enter a number");
    }
}
于 2012-05-27T05:18:48.530 に答える