该方法取任何名称并测试字符是元音还是辅音。如果它是一个元音,它会使字符大写,如果是辅音,则会使字符变为小写。有什么想法吗?我不知道如何在if语句中添加.toUpperCase
和.toLowerCase
。Java - 根据字符串是否为元音转换字符串中的字符
public static void parsing(String name[])
{
String temp = name[0];
int i = 0;
for(i = 0; i < temp.length(); i++)
{
if(temp.charAt(i) == 'a' || temp.charAt(i) == 'A' ||
temp.charAt(i) == 'e' || temp.charAt(i) == 'E' ||
temp.charAt(i) == 'i' || temp.charAt(i) == 'I' ||
temp.charAt(i) == 'o' || temp.charAt(i) == 'O' ||
temp.charAt(i) == 'u' || temp.charAt(i) == 'U')
{
System.out.print(temp.charAt(i).toUpperCase);
}//Obviously wrong but I don't know what to do.
else
{
System.out.print(temp.charAt(i).toLowerCase);
}//Obviously wrong but I don't know what to do.
}
那么当你运行这个时会发生什么? – Dutts 2013-02-20 17:29:07
String.equalsIgnoreCase是你的朋友 – NimChimpsky 2013-02-20 17:29:49