AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

# programming-basics: write a program to generate the below series

 4 6 12 18 30 42 60 programming x 169basics x 171 Posted On : 2017-07-28 12:03:29.0 rkjana 400 4

## Answers

 This is series of numbers where preceding and successive numbers are prime numbers. like 3 and 5 are prime with 4 as middle number. 5 and 7 are prime.... for 6 11 and 13 are prime..for 12 public class SeriesGenerator { public static void main(String[] args) { int startNumber=3; int totalElements=7; int[] series=new int[totalElements]; int previous=0; int i=0; while(i0 && startNumber-previous==2){ series[i]=previous+1; i++; } previous=startNumber; startNumber=startNumber+2; break; } startNumber=startNumber+2; } } for(int num:series){ System.out.print(num+" "); } } private static boolean isPrime(int num) { if (num < 2) return false; if (num == 2) return true; if (num % 2 == 0) return false; for (int i = 3; i * i <= num; i += 2) if (num % i == 0) return false; return true; } } Posted On : 2017-07-28 20:43:48 Satisfied : 1 Yes  2 No Rishi Kumar 523188237101Reply This Thread 5

Post Answer
Please Login First to Post Answer: Login

 Answer: