samedi 23 janvier 2021

Java Best Practices - Random Numbers [closed]

What is a better way to write the code below? Assume I'm only interested in type int for exactly 5 variables. It's working fine, but it seems like there would be a cleaner way to achieve the same thing. I would like to use something like:

    private int def = abc.nextInt(); 

However, I can't invoke nextInt() on a primitive type. Should I be creating these as a List?

private int abc = (int)(Math.random() * 1000);
private int def = (int)(Math.random() * 1000);
private int ghi = (int)(Math.random() * 1000);
private int jkl = (int)(Math.random() * 1000);
private int mno = (int)(Math.random() * 1000);



Aucun commentaire:

Enregistrer un commentaire