samedi 20 janvier 2018

How to print a random number with random method in constructor? [JAVA]

I want to use a method called printOneRandom to print a random number, but I am only allowed to create one single instance of Random in the constructor. (I need to create a similar method which uses Random again later) My code:

import java.util.Random;

public class RandomNumberHandler
{

public RandomNumberHandler()
{
    Random rand = new Random();
}

public void printOneRandom(Random rand) {
    Random random = rand;
    System.out.println(random);

    }
}

I get no output. Thanks




Aucun commentaire:

Enregistrer un commentaire