Hello I need help. I need to write a program that changes all upper case letters to lower case letters and all lower case letters to upper case then the vowels with an *...

it would look like this

normal= UppER loweR caSe

output should be this..

*PP*r L*W*r C*s*..

i already know how to change all lower case to upper case and vice versa if it's a sentence..but i don't know how to do it per letter..

can anyone pls help me..:cheesy:plzzzzz

Dani AI

Generated

Clarification of the required transformation (matches the example from ): vowels (A, E, I, O, U — case‑insensitive) become *; consonant letters have their case toggled (upper→lower, lower→upper); non‑letters (spaces, punctuation) are preserved. The sample "UppER loweR caSe" → "PPr LWr Cs" follows that rule.

Implementation approach: process the string one character at a time (the simplest and most predictable option, as suggested). Regular expressions can be used for parts of this, but attempting to do both the vowel-replace and case-toggle purely with regex is awkward and error‑prone (so ’s regex idea is fine in principle but needs careful ordering and extra work to preserve case). The code below is a compact, linear-time Java routine that applies the rule and avoids repeated string concatenation.

public static String flipAndStar(String s) {
    if (s == null) return null;
    StringBuilder out = new StringBuilder(s.length());
    for (char ch : s.toCharArray()) {
        char lower = Character.toLowerCase(ch);
        if ("aeiou".indexOf(lower) >= 0) {
            out.append('*');
        } else if (Character.isLetter(ch)) {
            out.append(Character.isUpperCase(ch)
                       ? Character.toLowerCase(ch)
                       : Character.toUpperCase(ch));
        } else {
            out.append(ch);
        }
    }
    return out.toString();
}

Notes and edge cases: the routine treats only ASCII vowels; accented vowels (á, é, ñ, etc.) are treated as letters but not matched as vowels unless normalized or added to the vowel set. The method is O(n) time and O(n) extra space (one StringBuilder). For full Unicode/code‑point safety (surrogate pairs) iterate by code points instead of char and adapt the vowel check accordingly.

Recommended Answers

All 2 Replies

You have to analyze the input one character at a time...

Say we have a string: myString

Set up a for loop with a lower limit of 0 and an upper limit of myString.length()-1 inclusive

Read each character one at a time with myString.charAt(int index) Analyze the single character. What is it? A vowel? Upper-case? Lower-case?

Append the new character to another string / a buffer.

Next character in the loop...

There are other ways to do this, but the above should work for general purpose.

Easiest (and fastest) is to use regular expressions to replace all uppercase letters with an asterisk, then call toUppercase() on the resulting string.
Far more elegant (and possibly faster, especially with long strings) than looping through every character.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.