Run error in last 2 test cases

Correct answer for first 4 test cases but run-error occured in last 2 test cases.
CODE:
import java.util.;
import java.io.
;
public class Main {
public static void main(String args[]) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();

    camel(str);

}

public static void camel(String str) {

    for(int i = 0; i < str.length(); ) {
        if(Character.isUpperCase(str.charAt(i)) && Character.isUpperCase(str.charAt(i+1))) {
            System.out.println(str.charAt(i));
            i++;
        }
        
            StringBuilder sb = new StringBuilder();
            sb.append(str.charAt(i));
            i++;

            while(!Character.isUpperCase(str.charAt(i))) {
                sb.append(str.charAt(i));
                i++;

                if(i == str.length())
                    break;
            }
            System.out.println(sb);
    }
}

}

Hi @Navneet01,your code is not working when given input HAPPY.

Each character of “HAPPY” is to be printed in same line or different?