简体   繁体   中英

How do i generate random number than recall those random number for using in another equation

I need help in java creating a code that will generate 10 random numbers between 8 and 32 (try to use a loop). For each random number generated, raise 2 to the power of the random number. Display the result to web page.

This is how you do it:

import java.util.*;

Random generator = new Random();
for(int i = 0; i < 10; i++) {
    int random = generator.nextInt(24) + 8;
    System.out.println(Math.pow(2, random));
}

This what you were looking for?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM