The random number should be between number1 and number2, an inclusive but after the first random number request, it goes outside my stipulation.
import java.util.*; public class RandomNumber{ public static void main(String[] args) { Random variable = new Random(); Scanner sc = new Scanner(System.in); System.out.println("Enter number 1: "); int number1 = sc.nextInt(); System.out.println("Enter number 2: "); int number2 = sc.nextInt(); if(number1>number2) { int a = (variable.nextInt((number1-number2) + number2)); System.out.println(a); } else { int a = (variable.nextInt((number2-number1) + number1)); System.out.println(a); } } }