Java program to generate random numbers
Java program to generate random numbers: This code generates random numbers in range 0 to 100 (both inclusive).
Download Random Numbers program class file.
Output of program:
nextInt(c) method returns next integer in 0 to c (both inclusive), c must be positive. To generate random float's use nextFloat which returns float between 0.0 to 1.0.
Java programming code
import java.util.*; class RandomNumbers { public static void main(String[] args) { int c; Random t = new Random(); // random integers in [0, 100] for (c = 1; c <= 10; c++) { System.out.println(t.nextInt(100)); } } }
Output of program:
nextInt(c) method returns next integer in 0 to c (both inclusive), c must be positive. To generate random float's use nextFloat which returns float between 0.0 to 1.0.
No comments:
Post a Comment