One test case is showing run tim error

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
String s = scn.next();
ArrayList list = new ArrayList();
for (int i = 0; i < s.length(); i++) {
if (Character.isUpperCase(s.charAt(i))) {
list.add(i);
}

	}
	int i = 0;
	for (int val : list) {
		System.out.println(s.substring(i, val));
		i = val;
	}
	System.out.println(s.substring(i, s.length()));

}

}

hi @guptadev354
you code is correct and its working fine but you can still optimize your code All you need to do is if the Character is an UpperCase then print a new Line otherwise simply print your character in any case. Another thing you need to handle is that you must not print a new Line if we encounter a UpperCase character in first line.