0
Random random = new Random();
int x = scanner.nextInt(bound:20)+1;

(bound:20) is not working to generate a random number from 1 to 20. what is the mistake I have done in this code?

not yours
  • 1
  • 2

1 Answers1

1
int x = scanner.nextInt(20) + 1; 

Just remove "bound :". The nextInt method expects an integer as an upper bound. So giving 20 as an argument is enough.

ShoqZz
  • 21
  • 5
  • Thanks!! But I have seen the (Bound) used in a video tutorial in exactly same line of code. Does the java version matter? – not yours Nov 13 '20 at 11:05
  • Thats probably just additional information (the name of the function's parameter) provided by the IDE. – ShoqZz Nov 14 '20 at 12:04