Q:

Problems with output of Sieve of Eratosthenes

This code sets a user submitted number as the upperbound of the array. Then, it sets all of the elements to true. After which it iterates through the array and sets all elements that would be in a non prime numbers position to false.
Then, it prints out all the true (prime) elements number in the array, not their indices. However, I can't figure out why my code here prints out 2, then all the odd numbers in the user-entered number range, since all the true elements should only be the actual prime numbers.
public static void main(String [] args){
    Scanner s = new Scanner(System.in);
    System.out.print("Please enter the largest integer to consider: ");
    int bounds = s.nextInt();
    boolean [] primes = new boolean[bounds];

    int j = 0;
    for(int i = 2; i < primes.length; i++) {
        primes[i] = true;
    }

    for(int x = 2; x < primes.length; x++) {
        for(int n = 2; j < primes.length; n++) {
            j = n * x;
            if(j < primes.length) {
                primes[j] = false;
            }
        }
    }

    for(int k = 0; k < primes.length; k++) {
        if(primes[k]) {
            System.out.println(k);
        }
    }
}

A:

You are using j to set the multiples of x to false.  That works for the first loop, when x is 2, but j isn't reset for the next x loop, and the n for loop isn't re-entered, so you get all the odd numbers printed.
Reset j to x before entering the j for loop.
for(int x = 2; x < primes.length; x++){
     j = x;
     for(int n = 2; j < primes.length; n++){

Output for input of 100:
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97

