0

私はこのコードを持っています

if(!(lotNo.charAt(0) >= "0" && (lotNo.charAt(0) <= "7"))) {
    // if the first character is not within these boundaries
    return false;
}
return true;

bad operator typeこの方法では、「 ? 」というエラーが表示されます。String の最初の文字が 0 から 7 の間であるかどうかを確認することになっていましたが、私は正しい行にいますか?

4

3 に答える 3

2

Char以内でなければなり'0'ません"0"。二つ目はString

于 2012-12-08T16:06:52.717 に答える
1

文字ではなく文字列と比較しています。試す:

if (!(lotNo.charAt(0) >= '0' && (lotNo.charAt(0) <= '7'))) { // if the first character is not within these boundaries
    return false;
}
return true;

"0"<-- 1 文字の文字列、'0'
'0'<-- 文字、文字'0'

于 2012-12-08T16:06:40.863 に答える
0

charAt(int index) メソッドの戻り値の型は char です。しかし、あなたはそれを文字列と比較しているので、あなたは得るのですbad operator type

于 2012-12-08T16:11:49.373 に答える