Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试确定字符串在Java中是否只包含字母_Java_String_Loops_For Loop_Char - Fatal编程技术网

尝试确定字符串在Java中是否只包含字母

尝试确定字符串在Java中是否只包含字母,java,string,loops,for-loop,char,Java,String,Loops,For Loop,Char,我的代码如下: } else if (words.toUpperCase().equals(words)) { for (int i = 0; words.length() > i; i++){ thisLetter = words.charAt(i); letter = thisLetter.isLetter(); if (!letter){ break; } } 字母是布尔值,thisLetter是字

我的代码如下:

} else if (words.toUpperCase().equals(words)) {
    for (int i = 0; words.length() > i; i++){
      thisLetter = words.charAt(i);
      letter = thisLetter.isLetter();
      if (!letter){
        break;
      }
    }  
字母是布尔值,thisLetter是字符类型(不是字符)。 由于某些原因,我在编译时出现以下错误:

 no suitable method found for isLetter()
method java.lang.Character.isLetter(int) is not applicable
  (actual and formal argument lists differ in length)
method java.lang.Character.isLetter(char) is not applicable
  (actual and formal argument lists differ in length)

而不是
letter=thisLetter.isLetter()
,它返回一个原语
char
。编译器将返回的值自动装箱到
字符中

Character
没有方法
isleter()
,您应该尝试

letter = Character.isLetter(thisLetter);
当然,假设
这个字母
字符

有关更多详细信息,请咨询承租人:

boolean containsOnly = true;
for (int i = 0; i < words.length(); i++) {
    char theChar = words.charAt(i);
    int index = "Java".indexOf(theChar);
    if (index < 0) {
       containsOnly = false;
       break;
    }
}
boolean containsOnly=true;
for(int i=0;i
words.toUpperCase().equals(words)是什么意思?它必须是大写字母“J”吗?这段代码的重点是确定字符串是否都是大写字母。这段代码检查这一点,但如果单词中有非字母,它也会返回true。
thisLetter.isLetter()
是错误的。应该是
Character.isLetter(这封信)
。这很有效,谢谢!但是我所做的有什么问题?
Character
没有方法
isleter()
,它有一个名为
isleter(char)