This is my code :
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in) ;
String str = scan.next() ;
ArrayList<Integer> al = new ArrayList<Integer>() ;
for(int i = 0 ; i < str.length() ; i++ ){
for(int j = i+1 ; j < str.length() ; j++ ){
String s = str.substring(i,j) ;
int num = Integer.parseInt(s) ;
al.add(num) ;
}
}
isPrime(al) ;
}
public static void isPrime(ArrayList<Integer> al){
int count = 0 ;
for(int i = 0 ; i < al.size() ; i++){
boolean isPrime = true ;
if(al.get(i) == 0 || al.get(i) == 1)
isPrime = false ;
for(int j = 2 ; j <= Math.sqrt(al.get(i)) ; j++){
if(al.get(i) % j == 0){
isPrime = false ;
break ;
}
}
if(isPrime)
count ++ ;
}
System.out.print(count) ;
}
}
Majority of my test cases have been failed. Can you tell me where did I made mistake?