Ask Question
10 June, 21:21

How do I write: "get a random number between - 10 and 11 but it cannot be 0"? (java)

+3
Answers (1)
  1. 10 June, 21:57
    0
    generate a random number in a known range and map the result to the range you want

    Explanation:

    Use any of the usual methods to get a random number in the range 0-20, then subtract 9. Use an IF statement to test if the result is 0. If it is, replace the value with - 10.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “How do I write: "get a random number between - 10 and 11 but it cannot be 0"? (java) ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers