Assume that String
FourZero ="0000";
String num = some String from input;
int difference = num.length()-FourZero.length();
for(int x=1; x<=difference; x++)
if(FourZero.equals(num.subString(x,x+4)));
System.out.println(num.subString(x-1,x+4));
I haven't tested the solution might be wrong.
you can just replace some output methods, but the genral idea is above.