Input
preBody = The AThe CThe IThe O{
I am trying to get the output as
The A
The C
The I
The O
and ignore a value less than 5(bodyCnt)[ { ]
So far What I did is.
int bodyCnt = 5
int cnt = 0;
String eachBody;
int extra = 0;
int limit = preBody.length();
while(limit >= bodyCnt){
eachBody = preBody.substring((cnt+extra), (bodyCnt+cnt));
cnt = eachBody.length();
extra = 1;
limit = limit - eachBody.length();
System.out.println("eachBody : -----"+eachBody);
}
Output
eachBody :----- The A
eachBody :----- The C
eachBody :----- The C
eachBody :----- The C
After 2 nd loop the data are same.
Am I doing anything wrong.
Or Can we approach the same in a better way?