2013-05-02 29 views
-1

出於某種原因,我的二維數組將會編譯並接受輸入,但實際上並不會打印數組。它應該能夠向前和向後打印數組,但沒有任何顯示。請幫忙!二維數組將在沒有打印結果的情況下編譯

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(); 
     } 

    } 

} 
+1

它打印.. !!再試一次...!! – 2013-05-02 06:13:01

回答

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 

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

相關問題