为什么这个int比较失败了?

时间:2016-01-20 22:31:26

标签: java android if-statement comparison

unparsedString 在断点处的值:

101010ten十<img src="E58D81.png" />ten, needle21Turn this character 45 degrees either way and you have the x used for the Roman numeral <b>ten</b>.* As a primitive, this character sometimes keeps its meaning of <i>ten</i> and sometimes signifies <i>needle</i>, this latter derived from the kanji for <i>needle</i> (Frame 292). Since the primitive is used in the kanji itself, there is no need to worry about confusing the two. In fact, we shall be following this procedure regularly.Two needles crossing marks the spot, or you can use the Roman character for ten (rotated 45 degrees).I scared away ten vampires with a single cross!15ジュウ、ジッ、ジュッとお、と十分(じっぷん): 10 minutes<br>十字路(じゅうじろ): crossroads<br>五十音(ごじゅうおん): the Japanese syllabary<br>十分(じゅうぶん): enough<br>十(じゅう): 10, ten<br>十(とお): 10, ten<br>十日(とおか): ten days, the tenth day of the month<br>二十歳(はたち): 20 years old, 20th year<br>二十日(はつか): twenty days, twentieth day of the month十字架 (じゅうじか), 十文字 (じゅうもんじ), 十 (と), 十 (とお)

ParseKanji 方法

 protected Kanji parseKanji(String unparsedString) {
    Kanji kanji = new Kanji();
    String[] fields = unparsedString.split("\u001F");

    int onI = findKatakanaIndex(fields); //17 while debugging
    int kunI = onI + 1;  //18, also checked

    kanji.setMeaning(fields[3]);
    kanji.setCharacter(fields[4]);
    kanji.setJH(fields[onI - 2]);
    kanji.setJTPL(fields[onI - 1]);
    kanji.setOnReading(fields[onI]);

    if (fields.length < kunI){ //returns false
    kanji.setKunReading(fields[onI + 1]);
    } else {
    Log.d("MyTests",  fields.length + " < " + kunI);
    Log.d("MyTests",  kanji.getCharacter() + " does not have a kun Reading");
    }

    return kanji;
}

logcat的

21 < 18
十 does not have a kun Reading

请注意,我以前使用onI + 1进行比较,而logcat的输出是:

21 < 171
十 does not have a kun Reading

1 个答案:

答案 0 :(得分:2)

21 < 18
十 does not have a kun Reading

这应该是打印的。您的日志语句错误,因为它位于else块中,您希望它打印“21&gt; = 18”。

21 < 171
十 does not have a kun Reading

当您使用+运算符时,是否有可能将17或1表示为字符串?这也会导致这个错误。你可以看到它增加了17和1来制作“171”而不是18。