+ 2

Scanner.nextInt() vs. Random.nextInt().

Is there any difference?

22nd Jun 2019, 10:47 AM
aMul
3 Answers
+ 7
Scanner.nextInt(); -> expects an Integer from the user (user input). Random.nextInt(); -> creates a random integer import java.util.Scanner; import java.util.Random; Scanner scan = new Scanner(System.in); int input = scan.nextInt(); System.out.println(input); Random rand = new Random(); //random number between 1-10 int num = rand.nextInt(10) + 1; //(6) + 1 would be a number between 1 - 6 //(6) -> 0 - 5 System.out.println(num);
22nd Jun 2019, 11:45 AM
Denise Roßberg
Denise Roßberg - avatar
+ 4
Your welcome :)
22nd Jun 2019, 12:13 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thanks denise
22nd Jun 2019, 12:12 PM
aMul