Wednesday, 10 July 2013

Rolling a dice by java Program(Random number Generator)

Generating a Random Number in java is pretty easy by using Random() method in java. by using it we can create a simple dice game
Program:

import java.util.*;

class apple

{

 public static void main(String[] args)

{

  Random dice = new Random();

  int roll;

  for (int j = 1; j <= 1; j++)

{

   roll = 1 + dice.nextInt(6);

   System.out.println(roll + "");

  }

 }

}

Output: it will randomly changed when ever you run this program from 1 to 6 

No comments:

Post a Comment