Discuss / Java / 提问和提交作业

提问和提交作业

Topic source

文德渊博

#1 Created at ... [Delete] [Delete and Lock User]
  • int indexOf(int ch, int fromIndex):根据字符查找,但指定起始位置;

  • 这个参数ch根据字符查找,不应该是char类型吗

  •     public void setName(String...strings){

            this.name="";

            for (String string : strings) {

                this.name=this.name+string+” “;

            }

        }

Fwmmmm-

#2 Created at ... [Delete] [Delete and Lock User]

在java里你可以给ch赋值随便某一个值啊   然后用Ascii码比较  大概就是这个意思

廖雪峰

#3 Created at ... [Delete] [Delete and Lock User]

char类型的unicode编码用int表示:

"abc".indexOf('a'); // ok
"abc".indexOf(97); // ok
int ch = 'a'; // ok

Black·Peter

#4 Created at ... [Delete] [Delete and Lock User]

传入char类型的参数时,实际上会进行隐式类型转换。char类型是一个16位的Unicode字符,而int类型是32位的整数。因此,可以将char类型的参数隐式转换为int类型,然后作为参数传入indexOf方法。这种隐式类型转换是Java语言中的一种自动类型转换规则。


  • 1

Reply