+ 2
Scanner.nextInt() vs. Random.nextInt().
Is there any difference?
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);
+ 4
Your welcome :)
+ 1
Thanks denise