Integer output from any 0 to 100 (java)

Asked 2 years ago, Updated 2 years ago, 29 views

    System.out.println(Math.random()*100 + 1);
    System.out.println((int)Math.random() * 101);
    System.out.println((int)Math.random() * 100);
    System.out.println((int)Math.random() * 100 + 1);

Which command is enforced first in this problem? After outputting a random number up to 0.0<=x<1, do you perform a later operation? The answer is the second question, but I don't understand it well, so I'm asking you this question!

java

2022-09-22 10:37

1 Answers

I think the question is weird.

If you make an arbitrary integer and divide it by 101, the remainder that you can get is from 0 to 100.


2022-09-22 10:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.