Qualcomm Interview Question

Grails and groovy with java based questions. They asked about java program to generate prime number till nth digit.

Interview Answer

Anonymous

Jan 24, 2017

private static void primeNumber(long limit){ long i, num; int cnt; for(i = 1; i = 1 ; num--){ if(i % num == 0){ cnt += 1; } } if(cnt == 2){ System.out.print(""+ i +" "); } } } pass '999999999' as an argument to above function it will print all the prime numbers in between (0 -999999999)