Java 需要阵列列表的指导吗

Java 需要阵列列表的指导吗,java,arrays,Java,Arrays,我该如何让我的txt输出以下格式!它只输出我输入的第一行,但希望它看起来像以下>> 这是我希望输出的外观示例- import java.io.FileOutputStream; 导入java.io.IOException; 导入java.io[在此处输入图像描述][1].PrintWriter; 导入java.util.Scanner; 导入java.util.ArrayList; 导入java.util.List; 公开课游戏分数{ 私有静态字符[]输入; 公共静态void main(字符串[

我该如何让我的txt输出以下格式!它只输出我输入的第一行,但希望它看起来像以下>>

这是我希望输出的外观示例-

import java.io.FileOutputStream;
导入java.io.IOException;
导入java.io[在此处输入图像描述][1].PrintWriter;
导入java.util.Scanner;
导入java.util.ArrayList;
导入java.util.List;
公开课游戏分数{
私有静态字符[]输入;
公共静态void main(字符串[]args){
int[]分钟播放=新int[100];
字符串gamerName、gamerReport;
字符串[]游戏名=新字符串[100];
整数[]高分=新整数[100];
@抑制警告(“资源”)
扫描仪扫描=新扫描仪(System.in);
System.out.println(“--------------游戏分数报告生成器-----------------”;
System.out.println(“”);
System.out.println(“输入您的姓名”);
gamerName=Scan.nextLine();
布尔值isEmpty=gamerName==null | | gamerName.trim().length()==0;
如果(我是空的){
System.out.print(“输入您的姓名”);
gamerName=Scan.nextLine();
}
System.out.println(“以该格式输入详细信息-“+”-->”);
System.out.println(“”);
System.out.println(“游戏:成就分数:播放分钟”);
gamerReport=Scan.nextLine();
扫描仪=新的扫描仪(System.in);
List al=新的ArrayList();
字符串字;
而(scanner.hasNextLine()){
word=scanner.nextLine();
如果(字!=null){
word=word.trim();
if(word.equalsIgnoreCase(“quit”){
打破
}
加(字);
}否则{
打破
}
}
字符串[]splitUpReport;
splitUpReport=gamerReport.split(“:”);
int i=0;
gameNames[i]=splitUpReport[0];
highScores[i]=Integer.parseInt(splitUpReport[1].trim());
minutesPlayed[i]=Integer.parseInt(splitUpReport[2].trim());
尝试
{
PrintWriter writer=新的PrintWriter(新文件输出流(“Gaming Report Data.txt”,true));
writer.println(“玩家:+gamerName”);
writer.println();
writer.println(“-------------------------------------”);
writer.println();
String[]report=gamerReport.split(“:”);
writer.println(“游戏:“+report[0]+”,score=“+report[1]+”,minutes played=“+report[2]);
//println(“玩的游戏:+玩的分钟”);
writer.close();
}捕获(IOE异常)
{
System.err.println(“您在数据输入方面出错”);
}
System.out.println(“你已经退出了!”);
}
公共静态字符[]getInput(){
返回输入;
}
公共静态void setInput(char[]输入){
GAMESCORE.input=输入;
}
}
变量“gamerReport”是为第一行设置的,除了打印它之外,再也不会碰它,列表“al”中添加了内容,但从未使用过。也许试试这样的

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;



public class GAMESCORE {

private static char[] input;

public static void main(String[] args) {

    int totalGames, totalAchievements, totalTime;

    totalGames = 0;
    totalAchievements = 0;
    totalTime = 0;

    String gamerName, gamerReport;

    @SuppressWarnings("resource")
    Scanner Scan = new Scanner(System.in);


    System.out.println("-------------- Game Score Report Generator --------------");
    System.out.println("     ");


    System.out.println("Enter Your Name");
    gamerName = Scan.nextLine();
    boolean isEmpty = gamerName == null || gamerName.trim().length() == 0;

    if (isEmpty) {

        System.out.print("Enter your Name.");

        gamerName = Scan.nextLine();
    }



    System.out.println("Enter details in this format - " + " -->");
    System.out.println("    ");



    System.out.println("Game : Achievement Score : Minutes Played");
    gamerReport = Scan.nextLine();
    Scanner scanner = new Scanner(System.in);

    List<String> al = new ArrayList<String>();
    String word;
    while (scanner.hasNextLine()) {
        word = scanner.nextLine();
        if (word != null) {
            word = word.trim();
            if (word.equalsIgnoreCase("quit")) {
                break;
            }
            al.add(word);
        } else {
            break;
        }
    }




    try
    {

        PrintWriter writer = new PrintWriter(new FileOutputStream("Gaming Report Data.txt", true));

        writer.println("Player : " + gamerName);
        writer.println();
        writer.println("--------------------------------");
        writer.println();
        for(String listString : al){
            String[] splitUpReport;
            splitUpReport = listString.split(":");

            writer.println("Game: " + splitUpReport[0].trim() + ", score= " + splitUpReport[1].trim() + ", minutes played= " +splitUpReport[2].trim());

            totalGames++;
            totalTime += Integer.parseInt(splitUpReport[2].trim());
            totalAchievements += Integer.parseInt(splitUpReport[1].trim());
        }

        writer.println();
        writer.println("--------------------------------");
        writer.println();
        writer.println("Games Played: " + String.valueOf(totalGames));
        writer.println("Total Achievement: " + String.valueOf(totalAchievements));
        writer.println("Total Time: " + String.valueOf(totalTime) + " (" + String.valueOf(totalTime/60) + " hours and " + String.valueOf(totalTime%60) + " minutes)");
        //writer.println("Games Played : " + minutesPlayed);
        writer.close();





    } catch (IOException e)
    {
        System.err.println("You have made an error with data input");
    }



    System.out.println("You have quit!");
}





public static char[] getInput() {
    return input;
}

public static void setInput(char[] input) {
    GAMESCORE.input = input;
}

}
导入java.io.File;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入java.io.PrintWriter;
导入java.util.Scanner;
导入java.util.ArrayList;
导入java.util.List;
公开课游戏分数{
私有静态字符[]输入;
公共静态void main(字符串[]args){
积分totalGames、TotalAcgregations、totalTime;
totalGames=0;
总成就=0;
总时间=0;
字符串gamerName、gamerReport;
@抑制警告(“资源”)
扫描仪扫描=新扫描仪(System.in);
System.out.println(“--------------游戏分数报告生成器-----------------”;
System.out.println(“”);
System.out.println(“输入您的姓名”);
gamerName=Scan.nextLine();
布尔值isEmpty=gamerName==null | | gamerName.trim().length()==0;
如果(我是空的){
System.out.print(“输入您的姓名”);
gamerName=Scan.nextLine();
}
System.out.println(“以该格式输入详细信息-“+”-->”);
System.out.println(“”);
System.out.println(“游戏:成就分数:播放分钟”);
gamerReport=Scan.nextLine();
扫描仪=新的扫描仪(System.in);
List al=新的ArrayList();
字符串字;
while(scanner.hasNextLine()){
word=scanner.nextLine();
if(word!=null){
word=word.trim();
if(word.equalsIgnoreCase(“退出”)){
打破
}
加(字);
}否则{
打破
}
}
尝试
{
PrintWriter writer=新的PrintWriter(新文件输出流(“Gaming Report Data.txt”,true));
writer.println(“玩家:+gamerName”);
writer.println();
writer.println(“-------------------------------------”);
writer.println();
for(字符串列表字符串:al){
字符串[]splitUpReport;
splitUpReport=listString.split(“:”);
writer.println(“游戏:+splitUpReport[0]。trim()+”,score=“+splitUpReport[1]。trim()+”,播放分钟数=“+splitUpReport[2]。trim());
totalGames++;
totalTime+=Integer.parseInt(splitUpReport[2].trim());
TotalProgressions+=Integer.parseInt(splitUpReport[1].trim());
}
writer.println();
writer.println(“-------------------------------------”);
writer.println();
writer.println(“玩的游戏:+String.valueOf(totalGames));
writer.println(“总成就:+String.valueOf(总成就));
writer.println(“总时间:“+String.valueOf(totalTime)+”(“+String.valueOf(
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;



public class GAMESCORE {

private static char[] input;

public static void main(String[] args) {

    int totalGames, totalAchievements, totalTime;

    totalGames = 0;
    totalAchievements = 0;
    totalTime = 0;

    String gamerName, gamerReport;

    @SuppressWarnings("resource")
    Scanner Scan = new Scanner(System.in);


    System.out.println("-------------- Game Score Report Generator --------------");
    System.out.println("     ");


    System.out.println("Enter Your Name");
    gamerName = Scan.nextLine();
    boolean isEmpty = gamerName == null || gamerName.trim().length() == 0;

    if (isEmpty) {

        System.out.print("Enter your Name.");

        gamerName = Scan.nextLine();
    }



    System.out.println("Enter details in this format - " + " -->");
    System.out.println("    ");



    System.out.println("Game : Achievement Score : Minutes Played");
    gamerReport = Scan.nextLine();
    Scanner scanner = new Scanner(System.in);

    List<String> al = new ArrayList<String>();
    String word;
    while (scanner.hasNextLine()) {
        word = scanner.nextLine();
        if (word != null) {
            word = word.trim();
            if (word.equalsIgnoreCase("quit")) {
                break;
            }
            al.add(word);
        } else {
            break;
        }
    }




    try
    {

        PrintWriter writer = new PrintWriter(new FileOutputStream("Gaming Report Data.txt", true));

        writer.println("Player : " + gamerName);
        writer.println();
        writer.println("--------------------------------");
        writer.println();
        for(String listString : al){
            String[] splitUpReport;
            splitUpReport = listString.split(":");

            writer.println("Game: " + splitUpReport[0].trim() + ", score= " + splitUpReport[1].trim() + ", minutes played= " +splitUpReport[2].trim());

            totalGames++;
            totalTime += Integer.parseInt(splitUpReport[2].trim());
            totalAchievements += Integer.parseInt(splitUpReport[1].trim());
        }

        writer.println();
        writer.println("--------------------------------");
        writer.println();
        writer.println("Games Played: " + String.valueOf(totalGames));
        writer.println("Total Achievement: " + String.valueOf(totalAchievements));
        writer.println("Total Time: " + String.valueOf(totalTime) + " (" + String.valueOf(totalTime/60) + " hours and " + String.valueOf(totalTime%60) + " minutes)");
        //writer.println("Games Played : " + minutesPlayed);
        writer.close();





    } catch (IOException e)
    {
        System.err.println("You have made an error with data input");
    }



    System.out.println("You have quit!");
}





public static char[] getInput() {
    return input;
}

public static void setInput(char[] input) {
    GAMESCORE.input = input;
}

}