编辑代码

public class NumberStr {
    public static void main(String[] args) {
        //Scanner sc = new Scanner(System.in);
        //String[] param = sc.nextLine().split(" ");
        //int n = Integer.parseInt(param[0]);//数字串的长度
        //int k = Integer.parseInt(param[1]);//能被那个数整除
        //String numStr = sc.nextLine();
        int n = 4;
        int k = 3;
        String numStr = "1423";
        List list = show(numStr);
        int count = 0;
        for (int i = 0; i < n; i++) {
            for(int j = i; j < n; j++){

            }
            int cur = 0;
            int m = 0;
            for (int j = i; j < n; j++) {
                cur = (cur * 10 + (Integer.parseInt(numStr.charAt(j)+"")));
                m = cur % k;
                if (m==0) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }

	public static List show( String str){  
        List list= new ArrayList<>();
        for(int i = 0; i < str.length(); i++){
            for (int j = i+1; j<=str.length(); j++){
                list.add(str.substring(i,j));
                System.out.println(str.substring(i,j));
                return list;
            }
        }
    }
}