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?
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.