該方法取任何名稱並測試字符是元音還是輔音。如果它是一個元音,它會使字符大寫,如果是輔音,則會使字符變爲小寫。有什麼想法嗎?我不知道如何在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