What it the error with my code

Scanner sc = new Scanner(System.in);
	String str = sc.nextLine();
	boolean flag = false ;
	
	 //convert String to char array
    char[] charArray = str.toCharArray();
	
	for(int i=0;i<str.length();i++) {
		if(Character.isUpperCase(charArray[i])) {
			String temp = str.substring(0,i+1);
			System.out.println(temp);
			str = str.substring(i+1);
		}
	}