-1

出于某种原因,我的二维数组将编译并接受输入,但实际上不会打印数组。它应该能够向前和向后打印 Array,但什么也没有出现。请帮忙!

import java.util.Scanner;
public class Assignment7 {    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("input row and column dimensions with a space separating them:");
        int[][] array = new int[scan.nextInt()][scan.nextInt()];  // scans input for array dimensions



        for(int row = 0; row < array.length; row++) //row
        {           
            for(int col = 0; col < array[row].length; col++) //column
            {
                array[row][col] = scan.nextInt();
            }
        }
        System.out.println("Array forward");


        for(int row = 0; row < array.length; row++){            
            for(int col = 0; col < array[row].length; col++){
                // print number followed by a space
                System.out.print(array[row][col] + " ");
            }
            System.out.println(); 
        }        
        System.out.println("Array backwards");        
        for(int row = array.length-1; row >= 0; row--){
            for(int col = array[row].length-1; col >= 0; col--)
            {
                System.out.print(array[row][col] + " ");
            }
            System.out.println();
        }

    }

}
4

1 回答 1

0

输入尺寸后,您还必须输入数组的值。之后我得到这个输出:

input row and column dimensions with a space separating them:
3 2
1 2 3 4 5 6
Array forward
1 2 
3 4 
5 6 
Array backwards
6 5 
4 3 
2 1 

所以它似乎工作正常。:)

于 2013-05-02T06:14:46.470 回答