我试图用for循环来检查数组中的每个字符并打印字符,它在数组中的位置以及它是什么类型的字符(元音,辅音等)。我有这个至今:使用for循环检查数组
char[] myName = new char[] {'J', 'o', 'h', 'n', ' ', 'D', 'o', 'e'};
System.out.print("\nMy name is: ");
for(int index=0; index < myName.length ; index++)
System.out.print(myName[index]);
for(char c : myName) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
{
System.out.println("The character located at position is a vowel.");
}
else if (c == 'j' || c == 'h' || c == 'n' || c == 'd')
{
System.out.println("The character located at position is a consonant.");
}
else if (c == ' ')
{
System.out.println("The character located at position is a space.");
}
如何打印的字符的位置
有什么错,你有什么? – Adam 2011-06-11 03:20:54
你正在寻找一种方法来确定当前正在检查的字母是元音还是辅音?看起来你在正确的轨道上,但你需要想出一个方法来确定那部分。 – 2011-06-11 03:22:36
我不知道如何打印它是什么类型的字符。 – JDB 2011-06-11 03:23:03