How to make array list for Lottery game?

When I tried to input duplicate number, program stopped and exited. But the expected output should be - the program must continue to run and ask the user to enter a different number to get the expected result.

11/17/2019 12:05:17 AM

Jorem May Magday

5 Answers

New Answer


You will have to share your code, or we won’t be able to tell what’s going on


import java.util.Scanner; import java.util.Random; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.TimeUnit; public class Lotto { public static void main(String[] args) { char play_again = 'y'; int[] numbers = new int[49]; int[] six_42 = new int[6]; int[] six_45 = new int[6]; int[] six_49 = new int[6]; int[] lucky_numbers = new int[3]; int[] userNumber = new int[6]; Scanner sc = new Scanner(System.in); int guess1, guess2, guess3, guess4, guess5, guess6; int win_num1, win_num2, win_num3, win_num4, win_num5, win_num6; int prize_six_42 = 1000; int prize_six_45 = 1000; int prize_six_49 = 1000; int prize_lucky_numbers_3 = 800; int prize_lucky_numbers_1 = 800; int i; SimpleDateFormat formatter = new SimpleDateFormat("MM dd yyyy"); Date date = new Date(); while (play_again == 'y') { System.out.println("---------------------------"); System.out.println("*** Welcome to IT Lotto ***"); System.out.println("-------------------




In sololearn you can only run input once and then resets, this code seems to be very large have you learned about methods


If some block of code will repeat more than once, make function and put all that code inside it. DRY