[Solved] Why do I need a temporary variable to store the value of a Random method? [closed]


You shall direct print it.

    import java.util.Random;

    public class compountInterest {

        public static void main(String[] args){

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

            System.out.println(new Random().nextInt(6));

//Appending empty char at start makes no difference

        }
    }

6

solved Why do I need a temporary variable to store the value of a Random method? [closed]