检查是否是字符串中的字母 [英] checking for is letter in a string
本文介绍了检查是否是字符串中的字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要求用户输入字符串,我想检查字母或数字,但是我是java的新手。这就是我到目前为止所拥有的
I am asking for user input in a string and i want to check for is alpha or numeric but i am new to java. this is what i have so far
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
isletter(s); // a call to the function
// function
public void isletter(String s)
{
for (int i = 0; i < s.length(); i++)
if (isLetter(s.charAt(i) ) ) {
System.out.println("is alpha = " + s);
}
else{
}
}
这是我在尝试通过dos进行编译时遇到的错误
Here is the error i am getting when trying to compile through dos
c:\programming>javac LexemesTokenizer4.java
LexemesTokenizer4.java:62: non-static method isletter(java.lang.String) cannot b
e referenced from a static context
isletter(s);
^
LexemesTokenizer4.java:71: non-static method isletter(java.lang.String) cannot b
e referenced from a static context
isletter(s);
^
LexemesTokenizer4.java:85: cannot find symbol
symbol : method isLetter(char)
location: class LexemesTokenizer4
if (isLetter(s.charAt(i) ) ) {
^
3 errors
c:\programming>
我知道这很简单吗?
推荐答案
在 isLetter
中, L
应该小写。 ( l
)。
In isLetter
, L
should be lowercase. (l
).
if (isLetter(s.charAt(i) ) )
// ^ lowercase
撇开那个错误,为什么要递归地调用方法 isletter
循环。
Keeping that mistake aside, why are you recursively calling the method isletter
in the loop.
这篇关于检查是否是字符串中的字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文