Fri Sep 10 2021
Random Number
Java Programming865 views
File Name: random-number.java
import java.io.*;
import java.util.Random;
class random_number {
public static void main(String args[ ]) {
int no;
/* Create object of Random class */
Random rn = new Random();
/* Generate random number from 1 to 10 */
no = rn.nextInt(10) + 1;
System.out.println("Random Number: "+no);
}
}
/* Output */
Random Number: 4
/* ------------------------- */
Random Number: 6
Reference:
Author:Geekboots