Use a StringBuilder to Mark Vowel : StringBuilder « Development Class « Java






Use a StringBuilder to Mark Vowel

  

import java.util.Scanner;

public class StringBuilderApp
{
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args)
    {
        System.out.print("Enter a string: ");
        String s = sc.nextLine();

        StringBuilder sb = new StringBuilder(s);

        int vowelCount = 0;

        for (int i = 0; i < s.length(); i++)
        {
            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'))
            {
                sb.setCharAt(i,
            }
        }
        System.out.println(s);
        System.out.println(sb.toString());
    }
}

   
  








Related examples in the same category

1.Check the capacity of StringBuilder object
2.Creates StringBuilder objects, append and insert text to them. Use the \n character for line breaks.
3.Remove substring from StringBuilder
4.Deletes text from the StringBuilder object
5.StringBuilderDemo: construct the same String three different waysStringBuilderDemo: construct the same String three different ways
6.Java 1.5 (5.0) new features: StringBuilderJava 1.5 (5.0) new features: StringBuilder
7.Palindrome with StringBuilderPalindrome with StringBuilder
8.StringBuilder.reverseStringBuilder.reverse