表中的java多维数组

iyr7buue  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(428)

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

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新手,所以我不擅长编程

m528fe3b

m528fe3b1#

这就是在表中打印数组的答案

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

                    }

相关问题