Can you point my mistake code is only accessing the first character

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String s=sc.next();
s=s.trim();
int j=0;
int cap=func(s);
for(int i=0;i<cap;i++){
while((s.charAt(j))>=65 && (s.charAt(j))<=90){
int k=j+1;
char l=s.charAt(k);
while(l>=97 && l<=122){
k++;
}
String b=s.substring(j,k);
System.out.println(b);
j=k;
}
}
}
public static int func(String a){
int count=0;
for(int i=0;i<a.length();i++){
char c=a.charAt(i);
if(c>=65 && c<=90){
count+=1;
}
}
return count;
}
}

in line no 12 of your code the val of char l isn’t changing if the value of k changes in the loop. It is the same value , thats getting into the loop repeatedly.