How come this loop doesn't print out six numbers?

Viewed 42
package p22_09_24;

public class Lotto2 {
    public static void main(String[] args) {
        for (int i=0; i <6; i++) {
            i = (int)(Math.random()*45)+1;
            System.out.println(i);
        }
    }
}

As you can see, the exit is under the 'for' which means it should loop six times, but the answer is only one num.

1 Answers
public class Random {

    public static void main(String[] args) {
        for (int i = 0; i < 6; i++)
        {
            int randomNumber = (int) (Math.random()*45)+1;
            System.out.println("Random number is: " + randomNumber);
        }
    }

}

use different name to store the random number.

Related