java需要数组列表的指导
我该如何让我的txt输出以下格式!它只输出我输入的第一行,但希望它如下所示>&燃气轮机
这是一个我希望输出看起来如何的示例-http://i.stack.imgur.com/7Lfr0.png
import java.io.FileOutputStream;
import java.io.IOException;
import java.io[enter image description here][1].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[] minutesPlayed = new int [100];
String gamerName, gamerReport;
String[] gameNames = new String[100];
int[] highScores = new int[100];
@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;
}
}
String[] 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());
try
{
PrintWriter writer = new PrintWriter(new FileOutputStream("Gaming Report Data.txt", true));
writer.println("Player : " + gamerName);
writer.println();
writer.println("--------------------------------");
writer.println();
String[] report = gamerReport.split(":");
writer.println("Game: " + report[0] + ", score= " +report[1] + ", minutes played= " +report[2]);
//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;
}
}
# 1 楼答案
变量“gamerReport”是为第一行设置的,除了打印它之外,再也不会碰它,列表“al”中添加了内容,但从未使用过。也许试试这样的