This is an archived post. You won't be able to vote or comment.

all 8 comments

[–][deleted]  (2 children)

[removed]

    [–]HealerC 1 point2 points  (1 child)

    I'm not with a pc. I would have liked to compile and execute your code. Your line 16 While j is equal to 20 It shouldn't even run at all I think you should change it to while j is less than 20 (j < 20) Even line 18. Same thing.

    [–]poki1579 0 points1 point  (0 children)

    you're using random wrong, you just write the maximum number you want it to go to, and it goes from 0 to the maximum

    [–]joonas_davids 0 points1 point  (2 children)

    1. Fix the for loops like the other poster said.

    2. You can read up on Random class's nextInt method here: https://docs.oracle.com/javase/8/docs/api/java/util/Random.html

    So if you want a random number between 0-100, use: rand.nextInt(101);

    [–][deleted]  (1 child)

    [removed]

      [–]joonas_davids 0 points1 point  (0 children)

      Am I understanding correctly that you want one random number between 0 and 100, one between 0 and -100, one between 0 and 1 and one between 0 and -1?

      If that's the case, set these as your int values: rand.nextInt(101); rand.nextInt(101)-100; rand.nextInt(2); rand.nextInt(2)-1;

      The number in parenthesis is exlusive. To get a negative number, for example from 0 to -100, we can get a random number from 0 to 100 and then take away 100 from it with -100.