- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我输入以下字符串:
" Hello party"
你怎么能只对链中的元音进行排序,而且是降序排列?
例如:
"Halle porty"
我尝试通过以下方式解决该问题,但是当我运行时它告诉我我有一个 ExeptionBounce 5。我该如何纠正它?我还被告知负责的线路如下:
if(cad[i].equalsIgnoreCase(vocal[j])
private String[]cad;
private String[]vocal={"a","e","i","o","u"};
private String resp="";
private String aux="":
private String []sort;
private int cont=0;
public String ordenar(String cadena)
{
cad= cadena.split("");
for(int i=0; i<cad.legth; i++)
{
for(int j=i, j<vocal.legth; j++)
{
if(cad[i].equalsIgnoreCase(vocal[j])
{
aux+=cad[i];
sort= aux.Split("");
Arrays.sort(sort);
for(int i=0; i<cad.legth; i++)
{
cad[i] = sort[k];
resp+=cad[i];
}
}
}
return resp;
}
最佳答案
您的代码甚至无法编译 - 您如何运行它?
为了回答您的问题,这里有一段代码,给定一个字符串将返回元音已排序的字符串:
public static boolean isVowel(char c) {
return "AEIOUaeiou".indexOf(c) != -1;
}
public static String sortVowelsOnly(String input) {
if (input == null) {
return input;
}
StringBuilder result = new StringBuilder(input);
//keep track at all positions where we saw a vowel
ArrayList<Integer> vowelPositions = new ArrayList<>();
//keep track of all vowels we saw so far
ArrayList<Character> vowels = new ArrayList<>();
for (int charPosition = 0; charPosition < input.length(); charPosition++) {
char currentChar = input.charAt(charPosition);
if(isVowel(currentChar)) {
vowelPositions.add(charPosition);
vowels.add(currentChar);
}
}
Collections.sort(vowels);
//now just iterate over all positions where we saw a vowel, and populate it with the vowels from the sorted list
for(Integer vowelPosition : vowelPositions) {
char vowel = vowels.remove(0);
result.setCharAt(vowelPosition, vowel);
}
return result.toString();
}
关于java - 句子中元音的降序排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56350177/
我试图在 haskell 上创建一个函数,我知道该函数的定义如下: justWithA : [Char] -> Bool justWithA [] = True justWithA (x:xs) |
我试图在 haskell 上创建一个函数,我知道该函数的定义如下: justWithA : [Char] -> Bool justWithA [] = True justWithA (x:xs) |
我正在尝试计算字符串中元音的总数。我正在使用 strlen 来获取字符串的总长度,但是当我尝试按每个字母对字符串进行计数时,它说 C++ 禁止比较。所以我假设我的 if 语句有问题。 #include
Task You are given a string . It consists of alphanumeric characters, spaces and symbols(+,-). Your
我刚刚开始用 C 语言编程,我必须创建一个程序来计算字符串有多少个元音。到目前为止我有这个: int a; int len = strlen(text)-1 for(a=0;a==len;++a){
尝试学习 Python 中的正则表达式以查找具有连续元音-辅音或辅音-元音组合的单词。我将如何在正则表达式中执行此操作?如果无法在 Regex 中完成,是否有一种在 Python 中执行此操作的有效方
我想输入 dagger-alif、dagger-waw 和 dagger-ya(也称为微型 alif、微型哇和微型 ya)作为 alif-wasla 使用 PC 阿拉伯语键盘。这些标记被使用帮助读者发
我正在尝试创建一个将文件上传到 FTP 服务器的批处理文件。除了一个特定文件夹的名称中包含突变/元音外,一切正常(无法更改。也就是文件夹名称中包含 ö。)。 我的问题是:有哪些选择可以实现这一目标?
我是一名优秀的程序员,十分优秀!