samedi 4 mars 2017

Why do I need a temporary variable to store the value of a Random method?

So I'm trying to run a simple 'generate random numbers' programme, and I can't understand why I need a temporary variable to store the value of the number generate. And also why do I print "" + variable instead of variable.

Example:

import java.util.Random;

public class compountInterest {

    public static void main(String[] args){

        Random dice = new Random();
        num = dice.nextInt(6);
        System.out.println("" + num);

    }
}




Aucun commentaire:

Enregistrer un commentaire