我想找到一种方法来使得输入字符串的元音在计入元音后变成大写。在字符串中大写元音java
import java.util.*;
public class Main {
public static void main(String[] args) {
// Vowels test = new Vowels(); //comment out this line
System.out.println("enter a string"); //Says enter String
Scanner kb = new Scanner(System.in); //Com reads the input
String str = kb.nextLine(); // this is the String variable to the input
// char vowel = str.charAt(p);
int count = 0; //this counts thee vowels
for(int p = 0; p<str.length(); p++) // p is the looping for the char vowel
{
char vowel = str.charAt(p);
//.Character.toUppercase(); //Character.toUpperCase doesn't work so much here...
// char vOwEl = Character.toUpperCase(vowel); //Adding a new char doesnt work either
switch (vowel)
{/* I forget the single quotes here...*/
case 'a':
// a-=32;
/*Character.toUpperCase('a');
count++;
break;//didn't work...*/
case 'e':
// e-=32;
/*Character.toUpperCase('e');
count++;
break; */
case 'i':
//i-=32;
/* Character.toUpperCase('i');
count++;
break;*/
case 'o':
// o-=32;
/* Character.toUpperCase('o');
count++;
break;*/
case 'u':
//u-=32;
//Character.toUpperCase('u');
count++;
//System.out.println("There are "+count+"vowels in the string: "+str);
break;
default:
//System.out.println("There is no vowels.");
// no code since it will print out "there is no vowels" a number of times
}
}
System.out.println("There are "+count+" vowels in the string: "+str);
// test.countVowels(str); //comment out this line
}
}
你的问题本质上是:““这里有一些广泛的需求,这里是一些代码”'和就是这样。这些问题非常难以回答,并且通常会被关闭。请告诉我们更多关于这个代码的内容,它做了什么,它没有做它应该做什么,请尝试提出一个更具体和可回答的问题,你可能会得到一个体面的,具体的答案。经验法则是问题的质量越好,质量越好,答案越快。 –
你有什么问题? –
你的代码绝对没有错,它计算元音。 – ergonaut