jeudi 27 septembre 2018

Printing Random Number Between 1 and 6 in Java [duplicate]

This question already has an answer here:

I am trying to print a random number between 1 and 6 in Java, but am having trouble doing so (getting errors). It is my first time using random numbers in Java. Can anybody tell me what I am doing wrong in my code?? I think I am actually calling the method right but some of the other code is not working properly.

import java.util.Random;
public class Random {

    public static void main(String args[]) {
        Random random = new Random();
        int ans = random.nextInt(7);
        System.out.println(ans);
    }
}




Aucun commentaire:

Enregistrer un commentaire