2017-09-19 2 views
0

私は最初に宣言した既定の配列に基づいて配列を印刷するには、ここで何が足りないのか分かりません。私はjavaが配列を印刷する他の方法を持っていることを知っていますが、(Javaのショートカットを使用するよりも)手順を長くするようにしていますので、他の言語に同じメソッドを適用する方が簡単です。誰かが私が持っているものを見て、私が見逃していることを教えてくれたら、私はそれを感謝します。クラス宣言を使用してintと文字列で配列を塗りつぶし

UPDATE:単純な解決策だったので、私はかなり気が気になりませんでしたが、今は別の問題に取り組んでいます。文字列とintを受け入れる配列が必要なので、パブリックな型の単語と数値でクラスを作成しましたが、配列を正しく埋める方法がわかりません。私は配列を埋めるために数字を設定していないことを知っていますが、誰かが私を理解するのを助けることができる場合、私は自分自身をもう一度やり遂げることができます。あなたはすべての値を印刷するループの前に

package employeetotalhours; 

import java.util.ArrayList; 

public class employeetotalhours { // main class declaration 

public static class Table{   // sub class declaration 
    public int number;  // establish input field values for ints 
    public String word;  // establish input field values for strings 
    Object array[]; 
} 

public static void main(String[] args){ // main method 

Table[] table = new Table[9]; 

Table word = null; 

table[0] = word; 

ArrayList<Table> Table = new ArrayList<Table>(); 

Table.add(new Table()); 

//   {{"Employee ","Su","M","T","W","T","F","Sa","Total"}, 
//   {"EmpID 0  ","4 ","2","5","3","4","5","8 ", "0"}, 
//   {"EmpID 1  ","1 ","7","8","4","3","3","4 ", "0"}, 
//   {"EmpID 2  ","2 ","3","3","4","3","3","2 ", "0"}, 
//   {"EmpID 3  ","3 ","3","3","7","3","4","1 ", "0"}, 
//   {"EmpID 4  ","1 ","3","2","4","3","6","3 ", "0"}, 
//   {"EmpID 5  ","5 ","3","4","4","6","3","4 ", "0"}, 
//   {"EmpID 6  ","8 ","3","7","4","8","3","8 ", "0"}, 
//   {"EmpID 7  ","2 ","6","3","5","9","2","7 ", "0"}}; 
    // all array data, multiple lines can be used as long as code is not closed with ; 

    int rows = 9; // establish array row size 

    int columns = 9; // establish array column size 

    for(int i = 0; i < rows; i++) 
    { 
     for(int j = 0; j < columns; j++) 
     { 
      System.out.print(table[i] + " "); 
     } 
      System.out.println(); 
    } 
} 
} 

答えて

1

あなたのそれは0

for(int i = 0; i < rows; i++) // loop to cycle through cells in array table 
    for(int j = 0; j < columns; j++) 
     array[i][j] = 0; 
012に再初期化された値である理由であるゼロにすべての配列要素を書いています
+0

さて、それではforループを削除する必要がありますか? –

+0

それをもう一度見て私はそれを参照してください、ダム感じ、私はチャンスを得るときにループなしでそれを試してみます –

+0

@SirPapilonius誰もが同じことを行う悪い感じていない:D –

4

、あなたはこのループがあります:あなたは要素を印刷するとき、あなたがそう0
に配列の各要素を設定し、このループでは

for(int i = 0; i < rows; i++) // loop to cycle through cells in array table 
    for(int j = 0; j < columns; j++) 
     array[i][j] = 0; 

を、すべてが0

関連する問題