How to set random int? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
18th Jun 2019, 10:33 AM
White_145 Gaming
White_145 Gaming - avatar
1 Answer
+ 2
I would recommend you to do it like this: Random random = new Random(); int test = random.nextInt(); But you have to import the Random class: import java.util.Random; A working example: import java.util.Random; public class Program { public static void main(String[] args) { Random rand = new Random(); int test = rand.nextInt(); System.out.println("The random integer is: " + test); } }
18th Jun 2019, 11:26 AM
TheLastCookie
TheLastCookie - avatar