谁能告诉我为什么会收到这些错误?如果是这样,我该如何修复它们?
Bingo.java:176: ']' expected
private static void makeCard(int[][] card, int[picks])
^
Bingo.java:176: ')' expected
private static void makeCard(int[][] card, int[picks])
^
Bingo.java:176: illegal start of type
private static void makeCard(int[][] card, int[picks])
^
Bingo.java:176: <identifier> expected
private static void makeCard(int[][] card, int[picks])
^
Bingo.java:177: ';' expected
{
^
Bingo.java:178: illegal start of type
System.out.println("Current Number Picks: \n");
^
Bingo.java:178: ';' expected
System.out.println("Current Number Picks: \n");
^
Bingo.java:178: invalid method declaration; return type required
System.out.println("Current Number Picks: \n");
^
Bingo.java:178: illegal start of type
System.out.println("Current Number Picks: \n");
^
Bingo.java:181: illegal start of type
for (int i=0; i<count; i++){
^
Bingo.java:181: ')' expected
for (int i=0; i<count; i++){
^
Bingo.java:181: illegal start of type
for (int i=0; i<count; i++){
^
Bingo.java:181: <identifier> expected
for (int i=0; i<count; i++){
^
Bingo.java:181: ';' expected
for (int i=0; i<count; i++){
^
Bingo.java:181: > expected
for (int i=0; i<count; i++){
^
Bingo.java:181: '(' expected
for (int i=0; i<count; i++){
^
Bingo.java:189: class, interface, or enum expected
private static void announceWin(int winFound, int numPicks)
^
Bingo.java:192: class, interface, or enum expected
}
^
Bingo.java:196: class, interface, or enum expected
for (int i = 0; i < numPicks; i++){
^
Bingo.java:196: class, interface, or enum expected
for (int i = 0; i < numPicks; i++){
^
Bingo.java:198: class, interface, or enum expected
return true;}
^
Bingo.java:202: class, interface, or enum expected
}
^
22 errors
以下是代码:
import java.util.*;
import java.io.*;
import java.util.Arrays;
public class Bingo
{
public static final int ROWS = 5;
public static final int COLS = 5;
public static final int VERTICAL = 1;
public static final int DIAGONAL = 2;
public static final int HORIZONTAL = 3;
public static int winFound;
public static int currPick = 0;
public static int randomPick;
public static int WinFound;
public static void main(String[] args)
{
int Totcards;
int[][] card = new int[ROWS][COLS];
fillCard (card);
printCard(card);
playGame(card);
printCard(card);
}
private static void fillCard (int[][] card)
{
// FileReader fileIn = new FileReader("Bingo.in");
// Bufferreader in = new Bufferreader(fileIn);
try {
Scanner scan = new Scanner(new File("bingo.in"));
for (int i=0; i<card.length; i++){
for (int j=0; j<card[0].length; j++){
card[i][j] = scan.nextInt();
}
}
} catch(FileNotFoundException fnfe) {
System.out.println(fnfe.getMessage());
}
}
private static void printCard (int[][] card)
{
System.out.println("\n\tYOUR BINGO CARD : ");
System.out.println("\n\tB I N G O");
System.out.println("\t----------------------");
for (int i=0; i<card.length; i++){
for (int j=0; j<card[0].length; j++){
System.out.print("\t" + card[i][j]);
}
System.out.print("\n");
}
}
private static void playGame (int[][] card)
{
int numPicks = 0;
while (true)
{
markCard (card); // Generate a random num & zero-it out
winFound = checkForWin(card); // Look for zero sums
numPicks++;
if (winFound != 0)
{
announceWin (winFound, numPicks);
return;
}
}
}
private static void markCard (int[][] card)
{
int randomPick = (int) (Math.random() * 74) + 1;
for (int j = 0; j < ROWS; j++){
for (int k = 0; k < COLS; k++){
if (card[j][k]==randomPick)
card[j][k] = 0;}
System.out.print(" " + randomPick);
}
}
private static int checkForWin(int[][] card)
{
int sum=0;
for (int i = 0; i < ROWS; i++)
{
sum = 0;
for (int j = 0; j < COLS; j++)
sum += card[i][j];
if (sum == 0)
return HORIZONTAL;
}
for (int j = 0; j < COLS; j++)
{
sum = 0;
for (int i = 0; i < ROWS; i++)
sum += card[i][j];
if (sum == 0)
return VERTICAL;
}
sum = 0;
for (int i = 0; i < ROWS; i++)
sum += card[i][ROWS-i-1];
if (sum == 0)
return DIAGONAL;
sum = 0;
for (int i = 0; i < ROWS; i++)
sum += card[i][i];
if (sum == 0)
return DIAGONAL;
return WinFound;
}
private static void makeCard(int[][] card, int[picks])
{
System.out.println("Current Number Picks: \n");
int count = 100;
int currPick = 0;
for (int i=0; i<count; i++){
currPick = (int)(Math.random() * 74) + 1;
System.out.print(" " + currPick + "\n");
picks[i] = currPick;
System.out.print("i: " + i);
}
}
private static void announceWin(int winFound, int numPicks)
{
System.out.println("winFound: " + winFound + "numpicks: " + numPicks);
}
private static boolean duplicate (int currPick, int[picks], int numPicks)
{
for (int i = 0; i < numPicks; i++){
if (picks[i] == currPick){
return true;}
}
return false;
}
}
答案 0 :(得分:0)
您正在接受错误的int数组参数。
你有int [picks]应该是int [] picks
import java.util.*;
import java.io.*;
import java.util.Arrays;
public class Bingo
{
public static final int ROWS = 5;
public static final int COLS = 5;
public static final int VERTICAL = 1;
public static final int DIAGONAL = 2;
public static final int HORIZONTAL = 3;
public static int winFound;
public static int currPick = 0;
public static int randomPick;
public static int WinFound;
public static void main(String[] args)
{
int Totcards;
int[][] card = new int[ROWS][COLS];
fillCard (card);
printCard(card);
playGame(card);
printCard(card);
}
private static void fillCard (int[][] card)
{
// FileReader fileIn = new FileReader("Bingo.in");
// Bufferreader in = new Bufferreader(fileIn);
try {
Scanner scan = new Scanner(new File("bingo.in"));
for (int i=0; i<card.length; i++){
for (int j=0; j<card[0].length; j++){
card[i][j] = scan.nextInt();
}
}
} catch(FileNotFoundException fnfe) {
System.out.println(fnfe.getMessage());
}
}
private static void printCard (int[][] card)
{
System.out.println("\n\tYOUR BINGO CARD : ");
System.out.println("\n\tB I N G O");
System.out.println("\t----------------------");
for (int i=0; i<card.length; i++){
for (int j=0; j<card[0].length; j++){
System.out.print("\t" + card[i][j]);
}
System.out.print("\n");
}
}
private static void playGame (int[][] card)
{
int numPicks = 0;
while (true)
{
markCard (card); // Generate a random num & zero-it out
winFound = checkForWin(card); // Look for zero sums
numPicks++;
if (winFound != 0)
{
announceWin (winFound, numPicks);
return;
}
}
}
private static void markCard (int[][] card)
{
int randomPick = (int) (Math.random() * 74) + 1;
for (int j = 0; j < ROWS; j++){
for (int k = 0; k < COLS; k++){
if (card[j][k]==randomPick)
card[j][k] = 0;}
System.out.print(" " + randomPick);
}
}
private static int checkForWin(int[][] card)
{
int sum=0;
for (int i = 0; i < ROWS; i++)
{
sum = 0;
for (int j = 0; j < COLS; j++)
sum += card[i][j];
if (sum == 0)
return HORIZONTAL;
}
for (int j = 0; j < COLS; j++)
{
sum = 0;
for (int i = 0; i < ROWS; i++)
sum += card[i][j];
if (sum == 0)
return VERTICAL;
}
sum = 0;
for (int i = 0; i < ROWS; i++)
sum += card[i][ROWS-i-1];
if (sum == 0)
return DIAGONAL;
sum = 0;
for (int i = 0; i < ROWS; i++)
sum += card[i][i];
if (sum == 0)
return DIAGONAL;
return WinFound;
}
private static void makeCard(int[][] card, int[] picks)
{
System.out.println("Current Number Picks: \n");
int count = 100;
int currPick = 0;
for (int i=0; i<count; i++){
currPick = (int)(Math.random() * 74) + 1;
System.out.print(" " + currPick + "\n");
picks[i] = currPick;
System.out.print("i: " + i);
}
}
private static void announceWin(int winFound, int numPicks)
{
System.out.println("winFound: " + winFound + "numpicks: " + numPicks);
}
private static boolean duplicate (int currPick, int[] picks, int numPicks)
{
for (int i = 0; i < numPicks; i++){
if (picks[i] == currPick){
return true;}
}
return false;
}
}
为我编译