import java.util.Random;
/** Generate 10 random integers in the range 0..99. */
public final class random {
public static final void main(String... aArgs){
log("Generating 100 random integers in range 0..99.");
//note a single Random object is reused here
Random randomGenerator = new Random();
for (int idx = 1; idx <= 10; ++idx){
int randomInt = randomGenerator.nextInt(10);
log("Generated : " + randomInt);
}
//log("Index 1"+randomInt());
log("Done.");
}
private static void log(String aMessage){
System.out.println(aMessage);
}
}
Hasil Compile
Generating 100 random integers in range 0..99.
Generated : 3
Generated : 8
Generated : 6
Generated : 3
Generated : 6
Generated : 2
Generated : 4
Generated : 9
Generated : 6
Generated : 2
Done.
terimakasih atas postingan anda.. cukup membantu :)
BalasHapus