-1 java loops switch-statement
我写了一个作业,试着计算一个字符串中每种元音的数字.
它编译得很好,但似乎在循环语句中循环,我看不出我做错了什么,尽管大约一个小时的谷歌搜索.
请帮忙!=]
import java.util.Scanner;
public class assignment3b
{
public static void main(String[] args)
{
int alpha=0, epsilon=0, india=0, oscar=0, uniform=0, position=0, length;
String input;
char letter;
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to the vowel parse-o-matic");
System.out.println("\nThis program will count all lower case vowels in whatever you type.");
System.out.print("\nPlease enter the word you'd like to have parsed : ");
input = scan.next();
System.out.println("\n\nThe word " + input + " has: "); // reprints the word before stripping spaces
input = input.replaceAll("\\s+",""); // Removes whitespace so they don't get counted.
while (position < input.length());
{
letter = input.charAt(position);
switch (letter)
{
case 'a':
alpha = alpha + 1;
position = position +1;
break;
case 'e':
epsilon = epsilon + 1;
position = position +1;
break;
case 'i':
india = india + 1;
position = position +1;
break;
case 'o':
oscar = oscar + 1;
position = position +1;
break;
case 'u':
uniform = uniform + 1;
position = position +1;
break;
default:
position++;
break;
}
System.out.println("a's = " + alpha);
System.out.println("e's = " + epsilon);
System.out.println("i's = " + india);
System.out.println("o's = " + oscar);
System.out.println("u's = " + uniform);
System.out.println("\nOther characters = " + (input.length() - alpha -epsilon - india -oscar - uniform));
}
}
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
125 次 |
| 最近记录: |