Why does it give me a 0 when my range is specifically 1~56?
Code:
//**********random()*************** public static int random(int a, int b) { return((int)((b - a + 1)*Math.random() + a)); } //**********superLottoNumbers()********* public static int[] superLottoNumbers() { int numZ[] = new int[6]; for(int h = 0; h <=4; h++) { numZ[h] = random(1,47); } Arrays.sort(numZ); numZ[5] = random(1,27); return(numZ); } //**********megaMillionNumbers()********* public static int[] megaMillionNumbers() { int numZ[] = new int[6]; for(int i = 0; i <= 4; i++) { numZ[i] = random(1,56); } Arrays.sort(numZ); numZ[5] = random(1,46); return(numZ); } public static void main(String args[]) { if(commandLine1(args[0]) == false) System.out.println("Not a valid type of Lottery"); //if(commandLine2(args[1]) == false) System.out.println("Not a valid number of tickets"); if(args[0].equalsIgnoreCase("sl")) { int num[] = new int[6]; num = superLottoNumbers(); for(int h: num) System.out.print(h+" "); } if(args[0].equalsIgnoreCase("mm")) { int num[] = new int[6]; num = megaMillionNumbers(); for(int i: num) System.out.print(i+" "); } } }
HELP ASAP. THanks