2016-03-28 23 views
0

入力およびユーザ入力 で多次元配列に文字列を格納し、私はGoogleからの多次元配列を学んできた、学ぶことは簡単だったが、私はどんなのscenerioに実装しなければならないとき!それを扱うことは困難です。私は、ユーザー入力を使用して多次元配列を宣言し、今はテーブルでこの配列を宣言したい。どうやって?これまでのところ Javaの多次元表中の配列

import java.util.Scanner; 

public class RugbyProject{ 
    final static int RESULT_POINTS_WIN = 2; 
    final static int RESULT_POINTS_DRAW = 1; 
    final static int RESULT_POINTS_LOSS = 0; 
    final static int GAME_POINTS_TRY = 5; 
    final static int GAME_POINTS_PENALTY = 3; 
    final static int GAME_POINTS_DROP_GOAL = 3; 
    final static int GAME_POINTS_CONVERSATION = 2; 

public class Stats { 

     // TODO Auto-generated method stub 
     int wins; 
     int draws; 
     int losses; 
     int tries; 
     int penalties; 
     int dropgoals; 
     int conversation; 
     int totalResultPoints = (wins * RESULT_POINTS_WIN) + (draws * RESULT_POINTS_DRAW) + (losses + RESULT_POINTS_LOSS) + (tries * GAME_POINTS_TRY) + 
           (penalties * GAME_POINTS_PENALTY) + (dropgoals * GAME_POINTS_DROP_GOAL) + (conversation * GAME_POINTS_CONVERSATION) ; 
     int averageScorePerMatch = (totalResultPoints/5); 

    } 
    public static void main(String args[]){ 
     String teams[] = {"Ireland","England","Scotland","Brazil","Irelan","Romania","Germany"}; 

     System.out.println("Welcome to the six nation ChampionShip"); 

     for(String element : teams){ 
      System.out.println("Enter number of wins, draws and losses for " + element); 
      Scanner myScanner = new Scanner(System.in); 
      int [] integer = new int[3]; 
      for(int i = 0; i<3; i++){ 
       integer[i] = myScanner.nextInt(); 
      } 
      System.out.println("ENter total try count, total penalty count ," + " total dropgoal count total conversation count for " + element); 
      Scanner myScanner2= new Scanner(System.in); 
      int[] integers2 = new int[3]; 
      for(int i=0; i<3; i++){ 
       integers2[i] = myScanner2.nextInt(); 
      } 
     } 
    } 
} 

は、私はちょうど入力を取得し、it.Iはので、私はテーブルの印刷配列に対する答えザッツプログラミング

+0

"この配列をテーブルに宣言したい" - それはどういう意味ですか? – Rehman

+0

テーブルにこのようなデータを印刷したい チームP W D L PtsFor/Aga Pts Diff Pts アイルランド イングランド ウェールズ フランス –

答えて

0

では良くないよJavaで新しいです保存しようとしている

public static void main(String args[]){ 
     String teams[] = {"Ireland","England"}; 
     int [] integer ={}; 
       int[] integers2 ={}; 
       int a=0; int b=3; 

     System.out.println("Welcome to the six nation ChampionShip"); 
     integer = new int[6]; 
     integers2 = new int[6]; 
     Scanner myScanner = new Scanner(System.in); 
       for(String element : teams){ 
      System.out.println("Enter number of wins, draws and losses for " + element); 
      //Scanner myScanner = new Scanner(System.in); 
         System.out.println("a="+a +" b="+b); 

      for(int i = a; i<b; i++){ 
       integer[i] = myScanner.nextInt(); 
      } 
      System.out.println("ENter total try count, total penalty count ," + " total dropgoal count total conversation count for " + element); 
      //Scanner myScanner2= new Scanner(System.in); 

      for(int i=a; i<b; i++){ 
       integers2[i] = myScanner.nextInt(); 
      } 
      a=3; 
         b=6; 

     } 

       System.out.println("Team \tP \tW \tD \tL \t"); 
       for(int j=0; j<teams.length; j++){ 
//        
        if(j==0){ 
         System.out.println(teams[j]+"\t"+(integer[j]+integer[j+1]+integer[j+2])+"\t"+integer[j]+"\t"+integer[j+1]+"\t"+integer[j+2]); 
          }else{ 
           System.out.println(teams[j]+"\t"+(integer[j+2]+integer[j+3]+integer[j+4])+"\t"+integer[j+2]+"\t"+integer[j+3]+"\t"+integer[j+4]); 
          } 

        }