Hello,
I am trying to randomly generate a number from a range of numbers.
public static void defineLucky(){ System.out.println("\nChoose a lucky number from a range " + "of numbers \n"); System.out.println("Enter lo number: "); int lo = scanner.nextInt(); System.out.println("Enter hi number: "); int hi = scanner.nextInt(); System.out.println(""); System.out.println("Your lucky number is: " + getLucky(lo,hi)); } public static int getLucky(int lo, int hi){ int total = 0; for (int i = lo; i <= hi; ++i){ total += i; } return total; }
Example: Right now when I put 5 and 10 in it is giving me 45 and I'm not really sure what needs done to fix this. I'm wanting it to give me a random number between 5 and 10.