繁体   English   中英

表中的Java多维数组

[英]Java multidimensional array in table

使用用户输入在多维数组中输入和存储字符串我已经从Google学习了多维数组,这很容易学习,但是当我必须在任何场景中实现时! 它很难处理。 我已经使用用户输入声明了多维数组,现在我想在table中声明此数组。 怎么样?

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

到目前为止,我只是试图获取输入并将其存储。我是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]);
                            }

                    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM