使用子字符串将用户输入的字符串中的所有元音替换为星号:
import java.util.Scanner; public class MarkVowels {/** 来自 时 代 J a v a**/ static Scanner sc = new Scanner(System.in); public static void main(String[] args) { System.out.print("Enter a string: "); String s = sc.nextLine(); String originalString = s; int vowelCount = 0; for (int i = 0; i < s.length(); i++) {//from N o w J a v a . c o m char c = s.charAt(i); if ( (c == 'A') || (c == 'a') || (c == 'E') || (c == 'e') || (c == 'I') || (c == 'i') || (c == 'O') || (c == 'o') || (c == 'U') || (c == 'u') ){ String front = s.substring(0, i);