【发布时间】:2020-04-02 06:39:23
【问题描述】:
我在为元音和辅音创建数组以及打印所有元音和辅音时遇到问题。请帮忙。我是 Java 新手 :(
public class VowCon {
public static void main(String[] args) {
String x;
Scanner in = new Scanner(System.in);
System.out.println("Please enter a STRING: ");
x = in .nextLine();
vowel = (a, e, i, o, u);
char[] vowname = x.toCharArray();
char[] consname = x.toCharArray();
}
for (int i = 0; i < x.length; i++) {
input = x.CharAt(i);
if (input == vowel) {
vowname[] = input;
else if (input != vowel) {
consname[] = input;
}
}
}
}
```
【问题讨论】:
-
请了解如何indent your code properly,帮助自己和他人。没有缩进基本上是不可能阅读代码的。您的 IDE 可以为您执行此操作。
-
vowel = a,e,i,o,u;- 你觉得这有什么作用? -
哦,对不起,我对数组很陌生,我还在学习这个
-
抱歉缩进是复制粘贴问题:(
-
@AndyTurner:同意...离开 Java 太久了。也许这样的事情会起作用:用
String vowel = "aeiou";替换这一行:vowel = a,e,i,o,u;(无论如何都不应该编译)和这个:if(input==vowel){用if (vowel.contains(input))。您的代码中还有其他小错误(不允许编译),例如您需要修复的vowname[]=input和consname[]=input;。