So I have this bingo program, as you can see I'm trying to print "YOU'VE WON WITH BLACKOUT" if the user has won with that pattern however the output looks like this:
Generating 5 random numbers...
48 YOU'VE WON WITH BLACKOUT
33 YOU'VE WON WITH BLACKOUT
28 YOU'VE WON WITH BLACKOUT
52 YOU'VE WON WITH BLACKOUT
24 YOU'VE WON WITH BLACKOUT
could someone help?
package Bingo;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Try {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Random random = new Random();
Scanner inp = new Scanner(System.in);
int enternum;
System.out.println("\n************** BINGO **************");
System.out.println("\nCreate your card!");
System.out.println("\nPlease input numbers from 1 - 15 in column B");
System.out.println("Please input numbers from 16 - 30 in column I");
System.out.println("Please input numbers from 31 - 45 in column N");
System.out.println("Please input numbers from 46 - 60 in column G");
System.out.println("Please input numbers from 61 - 75 in column O");
System.out.println("============================== ================");
System.out.println("Lets begin!");
int[][] card = new int[5][5];
System.out.println("Enter 5 numbers from 1-15 for column B:");
for (int i = 0; i < 5; i++) {
int num = 0;
boolean validInput = false;
while (!validInput) {
if (inp.hasNextInt()) {
num = inp.nextInt();
if (num >= 1 && num <= 15) {
validInput = true;
} else {
System.out.println("Invalid input. Please enter a number between 1-15.");
}
} else {
System.out.println("Invalid input. Please enter a number between 1-15.");
inp.next();
}
}
card[i][0] = num;
}
System.out.println("Enter 5 numbers from 16-30 for column I:");
for (int i = 0; i < 5; i++) {
int num = 0;
boolean validInput = false;
while (!validInput) {
if (inp.hasNextInt()) {
num = inp.nextInt();
if (num >= 16 && num <= 30) {
validInput = true;
} else {
System.out.println("Invalid input. Please enter a number between 16-30.");
}
} else {
System.out.println("Invalid input. Please enter a number between 16-30.");
inp.next();
}
}
card[i][1] = num;
}
System.out.println("Enter 5 numbers from 31-45 for column N:");
for (int i = 0; i < 5; i++) {
int num = 0;
boolean validInput = false;
while (!validInput) {
if (inp.hasNextInt()) {
num = inp.nextInt();
if (num >= 31 && num <= 45) {
validInput = true;
} else {
System.out.println("Invalid input. Please enter a number between 31-45.");
}
} else {
System.out.println("Invalid input. Please enter a number between 31-45.");
inp.next();
}
}
card[i][2] = num;
}
System.out.println("Enter 5 numbers from 46-60 for column G:");
for (int i = 0; i < 5; i++) {
int num = 0;
boolean validInput = false;
while (!validInput) {
if (inp.hasNextInt()) {
num = inp.nextInt();
if (num >= 46 && num <= 60) {
validInput = true;
} else {
System.out.println("Invalid input. Please enter a number between 46-60.");
}
} else {
System.out.println("Invalid input. Please enter a number between 46-60.");
inp.next();
}
}
card[i][3] = num;
}
System.out.println("Enter 5 numbers from 61-75 for column O:");
for (int i = 0; i < 5; i++) {
int num = 0;
boolean validInput = false;
while (!validInput) {
if (inp.hasNextInt()) {
num = inp.nextInt();
if (num >= 61 && num <= 75) {
validInput = true;
} else {
System.out.println("Invalid input. Please enter a number between 61-75.");
}
} else {
System.out.println("Invalid input. Please enter a number 1between 61-75.");
inp.next();
}
}
card[i][4] = num;
}
System.out.println("Here is your card");
// Display the Bingo card
System.out.println("B I N G O");
for (int i = 0; i < card.length; i++) {
for (int j = 0; j < card[i].length; j++) {
System.out.print(card[i][j] + "\t");
}
System.out.println();
}
System.out.println(" \n");
int bingo;
System.out.println("Select your winning pattern!");
System.out.println("1 - BLACKOUT BINGO");
System.out.println("2 - LINES BINGO");
System.out.println("3 - T's BINGO");
System.out.println("4 - U's BINGO");
System.out.println("5 - SQUARES BINGO");
bingo = inp.nextInt();
if (bingo == 1) {
System.out.println("YOU'VE CHOSEN BLACKOUT BINGO!");
} else if (bingo == 2) {
System.out.println("YOU'VE CHOSEN LINES BINGO!");
} else if (bingo == 3) {
System.out.println("YOU'VE CHOSEN T's BINGO!");
} else if (bingo == 4) {
System.out.println("YOU'VE CHOSEN U's BINGO!");
} else if (bingo == 5) {
System.out.println("YOU'VE CHOSEN SQUARES BINGO!");
}
boolean playing = true;
while (playing) {
System.out.println("Press 1 to generate 5 random numbers or 2 to quit:");
int choice = input.nextInt();
if (choice == 1) {
System.out.println("Generating 5 random numbers...");
int[] selectedNumbers = new int[5];
for (int i = 0; i < 5; i++) {
int randomNumber = random.nextInt(75) + 1;
selectedNumbers[i] = randomNumber;
System.out.print(selectedNumbers[i] + " ");
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 5; col++) {
if (card[row][col] == randomNumber) {
card[row][col] = -1;
break;
}
}
if (bingo == 1 && (card[row][0] == -1 || card[row][1] == -1 || card[row][2] == -1 || card[row][3] == -1 || card[row][4] == -1)) {
playing = false;
System.out.println("YOU'VE WON WITH BLACKOUT");
break;
}
System.out.println();
}
}
} else if (choice == 2) {
playing = false;
System.out.println("Quitting Bingo. Goodbye!");
} else {
System.out.println("Invalid input. Please enter 1 to generate 5 random numbers or 2 to quit.");
}
}
}
}