public class PrimeCheckerImpl {
/**
* @Srinivas Kumar
*/
public Map<Integer, Boolean> primeChecker(List<Integer> randList) {
int i,m=0,flag=0;
Map<Integer,Boolean> primeCheckMap=new HashMap<>();
Iterator<Integer> itrList= randList.iterator();
if(itrList.hasNext()){
int randNum=itrList.next();
m=randNum/2;
for(i=2;i<=m;i++){
if(randNum%i==0){
System.out.println("Number is not prime");
flag=1;
primeCheckMap.put(randNum, false);
break;
}
}
if(flag==0)
System.out.println("Number is prime");
primeCheckMap.put(randNum, true);
}
return primeCheckMap;
}
public static void main(String[] args) {
PrimeCheckerImpl look_up=new PrimeCheckerImpl ();
List<Integer> posNumList=new ArrayList<Integer>();
Random randomList=new Random();
Integer genNum=randomList.nextInt();
System.out.println(randomList.nextInt());
for (int i=0;i<10;i++){
IRandom randomnum=new Random();
if(randomnum>0){
posNumList.add(num);
}
}
Map<Integer, Boolean> primeList=look_up.primeChecker(posNumList);
/
System.out.println(primeList);
}
}
/**
* @Srinivas Kumar
*/
public Map<Integer, Boolean> primeChecker(List<Integer> randList) {
int i,m=0,flag=0;
Map<Integer,Boolean> primeCheckMap=new HashMap<>();
Iterator<Integer> itrList= randList.iterator();
if(itrList.hasNext()){
int randNum=itrList.next();
m=randNum/2;
for(i=2;i<=m;i++){
if(randNum%i==0){
System.out.println("Number is not prime");
flag=1;
primeCheckMap.put(randNum, false);
break;
}
}
if(flag==0)
System.out.println("Number is prime");
primeCheckMap.put(randNum, true);
}
return primeCheckMap;
}
public static void main(String[] args) {
PrimeCheckerImpl look_up=new PrimeCheckerImpl ();
List<Integer> posNumList=new ArrayList<Integer>();
Random randomList=new Random();
Integer genNum=randomList.nextInt();
System.out.println(randomList.nextInt());
for (int i=0;i<10;i++){
IRandom randomnum=new Random();
if(randomnum>0){
posNumList.add(num);
}
}
Map<Integer, Boolean> primeList=look_up.primeChecker(posNumList);
/
System.out.println(primeList);
}
}
0 comments: