我正在尝试为数组中的特定单词连续查找最多数量的辅音。我在中间有一个我评论过的while循环,但由于某种原因它没有执行。有谁知道为什么?此外,您可能会注意到我有一个 int 空格,因为我正在尝试查找 String[] 单词的子数组。我该怎么做呢?
import java.io.*;
import java.util.*
import java.util.Arrays;
public class Main
{
public static void main (String[] args)
{
System.out.print("Please enter a phrase to translate: ");
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
String[] words = str.split("\\s+");
int spaces = (word.length - 1);
for (int i = 0; i < words.length; i++)
{
String a = words[i].substring(0,1);
int k = a.length();
int n = words[i].length();
if (!(a.contains("a") || a.contains("e") || a.contains("i") || a.contains("o") || a.contains("u")))
{
while (k < 5) // start while
{
if (n > k)
{
a = words[i].substring(0,k);
k = k + 1;
}
}
} // end while
if (words[i].startsWith("a") || words[i].startsWith("e") || words[i].startsWith("i") || words[i].startsWith("o") || words[i].startsWith("u"))
{
System.out.print(words[i] + "way");
}
else if (!(a.contains("a") || a.contains("e") || a.contains("i") || a.contains("o") || a.contains("u")))
{
String answer = words[i].substring(k,n);
System.out.print(answer + a + "ay");
}
}
}
}