Reversing only vowels in a string Given a string, reverse only the vowels present in it and print the resulting string.
example
input: ransomware
output: rensamwora

Here is my solution:

import java.util.Scanner;

public class ReversingVowels {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int numberOfTestCases = scanner.nextInt();

        while (numberOfTestCases --&gt; 0) {
            StringBuilder stringWhoseVowelsShouldBeReversed = new StringBuilder(scanner.next());
            System.out.println(reverseVowels(stringWhoseVowelsShouldBeReversed));
        }

        scanner.close();
    }

    private static String reverseVowels(StringBuilder string) {

        if (string.length() == 0 || string.length() == 1) return string.toString();

        int start = 0;
        int end = string.length() - 1;

        while (true) {
            while (! isVowel(string.charAt(start))) {
                start++;
            } 
            while (! isVowel(string.charAt(end))) {
                end--;
            }
            if (start &gt;= end) {
                break;
            }
            else {
                swapVowels(string, start, end);
                start++;
                end--;
            }
        }
        return string.toString();
    }

    private static boolean isVowel(char character) {
        switch(character) {
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u': return true;
        default: return false;
        }
    }

    private static void swapVowels(StringBuilder string, int index1, int index2) {
        char tmp = string.charAt(index1);
        string.setCharAt(index1, string.charAt(index2));
        string.setCharAt(index2, tmp);
    }
}


Questions:


Are there any bad practises
Are there any issues
Can this be improved
1) No more than one instruction per line.

if (string.length() == 0 || string.length() == 1) return string.toString();


i.e.:

if (string.length() == 0 || string.length() == 1) {
    return string.toString();
}
// or, better:
// if (string.length() &lt; 2) {
//     return string.toString();     
// }


2) Your main while feels strange, I don't like this creative use of postdecrement and greater then operator

while (numberOfTestCases --&gt; 0)  // BAD! See https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c


In this case a for loop is better because you know the number of iterations.

3) while (true) is bad and force the developer to read all the code to understand how to break the loop

4) No need to pass a StringBuilder to reverseVowels: the method itself should create it.

5) Use temporary variables to improve readability:

...
for (int i = 0; i &lt; numberOfTestCases; i++) {
    String input = scanner.nextLine();

    String vowelsReversedString = reverseVowels(input);

    System.out.println("OUTPUT: " + vowelsReversedString);
}  
...

...
private static String reverseVowels(String string) {
    if (string == null || string.length() &lt; 2) {
        return string;
    }

    StringBuilder sb = new StringBuilder(string);

    int start = 0;
    int end = sb.length() - 1;

    while (start &lt; end) {
        ...
    }

    return sb.toString();
}
...