![]() Int n = 1.4 * MAX * Math.log(MAX) // Overestimate by 40% This is more of a matter of preference, but this is how I would format your code: ArrayList list = new ArrayList() įor (int i = 0 i result = new LinkedList() īoolean isPrimeArray = new boolean įor (int j = i i * j result = new LinkedList() Your bracing does not follow standard Java conventions. ![]() If ( isPrime ) // if it stays true, we will add it to our collectionĬount = list.size() // count equals size of collection at every turn IsPrime = false // however, if it is divided by any other less prime, isPrime will be false If ( number % list.get(i) = 0 ) // we check for every less prime While ( count != 100 ) // we want first 100 primeīoolean isPrime = true // we assume that the number is prime Int number = 3 // first prime number after 2 is 3 Int count = list.size() // count is our size it will be max 100 List.add(2) // first prime 2 goes to our collection I used the fact that, if the number is not divisible by any prime less than itself, it will be a new prime. ![]() what design would you use for printing first 100 prime numbers? ![]() I thought of this implementation, and I want to get feedback from you. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |