0

我需要制作一张不同价格的座位表。继承人我到目前为止。我无法制作一张桌子。

public class theatSeat {
public static final int rows=9;
public static final int cols=10;

public static void dispBox(int[][] a){
    for (int row=0;row<rows;row++){
        System.out.print((row+1)+" ");
        for (int col=0;col<cols;col++){
            System.out.print(a[row][col]+" ");
            System.out.println();
        }
    }

}//Sets the diplayed seating box

public static void getPrice(int[][]a){
}

public static void main(String[] args) {
    // TODO Auto-generated method stub

    int [] [] table = new int[rows] [cols];
    for(int row=0;row<rows;row++){
        for(int col=0;col<cols;col++){
            table[row][col]=0;
        }
    }
            dispBox(table);

}}//鳍。

4

1 回答 1

0

在您的循环中,您将所有值设为 0。您是否想要每个值都像随机值?像这样

Random random = new Random();
for(int row=0;row<rows;row++){
    for(int col=0;col<cols;col++){
        table[row][col]=random.nextInt(50);
    }
}

如果您在显示时遇到问题,请尝试此操作

public static void dispBox(int[][] a){
    for (int row=0;row<rows;row++){
        System.out.print((row+1)+" ");

        for (int col=0;col<cols;col++){
            System.out.print(a[row][col]+" ");
        }
        System.out.println();
        // this needs to go at the end of each line.
        // You were putting it at the end of each print
    }
}
于 2013-11-11T05:45:47.530 回答