I need help with the following question.
Print the binary version of numbers between (a,b) which do not have two or more consecutive 0s.
I have completed till the binary number part of fixed length in JAVA, but unable to use concept of range.
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int x = scn.nextInt();
int y = scn.nextInt();
meth45(0,new ArrayList<Integer>(),4);
}
private static void meth45(int i,ArrayList<Integer> ans,int n) {
if(i==n){
System.out.println(ans);
StringBuilder sb = new StringBuilder();
for (int i1 = 0 ; i1 <= ans.size() - 1; i1++) {
int num = ans.get(i1);
sb.append(num);
}
String result = sb.toString();
System.out.println(result);
return;
}
ans.add(1);
meth45(i+1,ans,n);
ans.remove(ans.size()-1);
if(ans.size()!=0&&ans.get(ans.size()-1)==0){
return;
}
else
ans.add(0);
meth45(i+1,ans,n);
ans.remove(ans.size()-1);
}
}Thanks in advance !!!