我正在研究这个非常简单的方法,我知道我非常接近完成它,但我错过了一个细节。我感谢任何帮助。谢谢。获取字符串中第一个字母的实例
/**
Gets the first letter in this string.
@return the FIRST LETTER, or "" if there are no letters.
add1=AD3F add2=EF4G result=32SFB (BUT THESE ARE RANDOM ONLY INTS AND CHARS)
*/
public String firstLetter()
{
String line = add1+add2+result;
for(int i=0; i<line.length(); i++){
char ch=new Character(line.charAt(i));
if(Character.isLetter(ch)){
System.out.println("This is the first letter"+ch);
return ch;
}
else
System.out.println("No it is not a character: "+ch);
return "";
}
非常感谢您对DNA先生的帮助。我还从你的代码中学习了铸造“返回Character.toString(ch)”我将分两步做,但你告诉我如何一步完成。谢谢。 – 2012-02-25 21:21:14