나는이 간단한 GUI 프로그램을 만들어 특정 문자 시퀀스의 모음과 자음을 센다.if-else 문에 어떤 문제가 있습니까?
다음//I initialized these variables:
public static int vowels = 0, consonants = 0, charac = 0;
public static String outputStr;
public static String conso = "bcdfghjklmnpqrstvwxyz";
public static String vow = "aeiou";
//Here's the code for my "count" button
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String userInput = jTextField1.getText();
userInput = userInput.toUpperCase();
conso = conso.toUpperCase();
vow = vow.toUpperCase();
String wordInput[] = userInput.split("");
vowels = 0;
consonants = 0;
charac = 0;
for(int i=0; i<wordInput.length; i++) {
for(int j=0; j<5; j++) {
char v = vow.charAt(j);
String VL = Character.toString(v);
if(VL.equals(wordInput[i])) {
vowels ++;
charac = 0;}
else {
charac += 1; }
}
for(int h=0; h<21; h++) {
char c = conso.charAt(h);
String CL = Character.toString(c);
if(CL.equals(wordInput[i])) {
consonants ++;
charac = 0; }
else {
charac += 1; }
}
}
String totalVow = Integer.toString(vowels);
String totalCons = Integer.toString(consonants);
jLabel5.setText(totalVow);
jLabel6.setText(totalCons);
//here's the if-else statement:
if (charac == 0) {
jLabel7.setText(" ");
}
else if (charac >= 1) {
jLabel7.setText("The sequence contains invalid characters.");
}
if (userInput.isEmpty()) {
jLabel7.setText("No input.");
}
}
무엇을의 : 카운터는 괜찮지 만, 나는 그 문자는 모음이나 자음 어느 때 메시지를 표시했던 경우-else 문에 문제가있어 ... 여기에 코드입니다
내가 특수 문자 또는 숫자가없는 문자의 "순서를"입력 : 것 같습니다. 그러나 그것은 여전히 모음과 자음 이외의 다른 문자가있는 메시지를 표시합니다. if-else 문에 문제가 있습니까? 도움을 주셔서 감사합니다 :)
나는 이것을 시험해 보았다! 게다가 코드가 좀 더 짧아졌습니다. 고마워요! @tobias_k –