English 中文(简体)
Java .charAt(一)比较问题
原标题:Java .charAt(i) comparison issue

为什么在把一个果园与另一个果园进行比较时,也必须从扼杀中去掉? 例如:

www.un.org/Depts/DGACM/index_spanish.htm 这并不奏效。

   while(i < t.length() && zeroCount < 5) {
        if(t.charAt(i) == 0){
            zeroCount++;
        }
        i++;
    }

Nor does this

char zero = 0;

      while(i < t.length() && zeroCount < 5) {
            if(t.charAt(i) == zero){
                zeroCount++;
            }
            i++;
        }

我之所以能够做到这一点,唯一的办法就是这样做。

String zeros = "0000000000";

      while(i < t.length() && zeroCount < 5) {
            if(t.charAt(i) == zeros.charAt(i)){
                zeroCount++;
            }
            i++;
        }

任何人如果做错事,或者做像头2例这样的事,就能够解释。 如果是,为什么?

最佳回答

阁下

char zero = 0;

iii

char zero =  0 ;

前者为零,后者为零。

This confusion is a rather unfortunate hang-over from C, iii char variables being treated as numbers as well as characters.

问题回答

你们正在研究的是特性0? 然后是0,而不是0。

您对统法协会编码价值0(aka U+0000,“null”特性)进行了比较,该数值与统法协会编码特性,代表0

Use 0 instead of 0:

while(i < t.length() && zeroCount < 5) {
    if(t.charAt(i) ==  0 ){
        zeroCount++;
    }
    i++;
}

使用0而不是0。

简单的答复是,数值<代码>0与代码<0>/code>不相同,该代码为48(IIRC)。

您应将其与代谢价值(charAt(i) = 0 或比照charAt(i)-0 = 0

这些其他答案是正确的,但你知道的一件非常重要的事情。 您永远不应使用<条码>。 您只应使用<条码>编码点At。

同样,你必须盲目使用<条码>i++/代码>,通过体积进行消费。 你们需要看看<代码>s.codePointAt(i) > 特征。 http://www.un.org i++ kicker。

例如,在<代码>上打印所有代码点。 在标准“U+”的代号中应用:

private static void say_U_contents(String s) { 
    System.out.print("U+");
    for (int i = 0; i < s.length(); i++) {
        System.out.printf("%X", s.codePointAt(i));
        if (s.codePointAt(i) > Character.MAX_VALUE) { i++; }  // UG!
        if (i+1 < s.length()) { System.out.printf("."); }
    }
}

这样,你就可以为相应的扼杀物产出如下:<编码>U+61.DF、U+3C3U+1F4A9.1F4A9.1F4A。 这最后一种情况是uD83DuDCA9uD83DuDCA9”,这只是一纸空文。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签