Java Random.nextInt()

Syntax

Random.nextInt() has the following syntax.

public int nextInt()

Example

In the following code shows how to use Random.nextInt() method.


/* www  . j  ava 2  s .  co  m*/

import java.util.Random;

public class Main {
   public static void main( String args[] ){

      Random randomno = new Random();
 
      // check next int value  
      System.out.println("Next int value: " + randomno.nextInt());
   }    
}

The code above generates the following result.