r/learnprogramming•
[deleted]

Don't quite understand what this beginners Java prime number lab is asking me to do, please hlep

Pseudocode Explanation of the Algorithm

Input: n = max number to examine (<= 500)

  1. Create an array with (n+1) elements: int [] values = new int[n + 1];
  1. Use a loop to fill array with 1s (1 = prime, 0 = non prime)
  1. Use a loop to examine elements at positions 2-n:

I understand the rest of the algorithm but I just have no clue what the second step means. Is it telling me to convert all prime numbers into 1s and all non prime numbers into 0s? How do I do that?

Posted Dec 2, 2011, 3:38 AM UTC

46
Loading comments…