What is wrong in my code?

package STRINGS;

import java.util.Scanner;

public class findingcbnumbers {

public static void main(String[] args) {
	Scanner scn = new Scanner(System.in);
	int n = scn.nextInt();
	String str="";
    for (int i=0;i<n;i++) {
    	String s=scn.next();
    	str=str+s;
    }
    cbno(str,1);
   
}
public static void cbno(String str,int vidx) {
	int count=0;
	if (vidx>=str.length()) {
		System.out.println(count);
	}
	
	for (int i=vidx;i<str.length();i++) {
		String a=str.substring(0,i);
		int a1=Stringtointeger( a,0);
		if (a1%2 !=0 && a1%3 !=0) {
			count++;
		}
	}
	cbno(str,vidx+1);
}
public static int Stringtointeger(String str,int lo) {
	int ch=0;
	if (lo>=str.length()) {
		return ch;
	}
	
	 ch=ch+str.charAt(lo)-'0';
	
	Stringtointeger(str,lo+1);
	return ch;
}

}

@harsh.hj,
Suggested approach:

  1. check for all sub-strings of the given string of digits, starting from the all strings of length 1 and then gradually checking for the strings of increasing size:

1.1. check if the sub-string is CB number: for this, create a function
1.1.1. if sub-string is 1 or 0 return false.
1.1.2. if sub-string is any of the {2,3,5,7,11,13,17,19,23,29}, then return true.
1.1.3. if sub-string is divisible by any of the {2,3,5,7,11,13,17,19,23,29}, then return false.
1.1.4. return false

1.2. now if it is a substring:
1.2.1. call a function that marks the index as visited for indexes which are part of that CB number.

1.3. increment the count for CB number.

  1. Print the count

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.