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