Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 控制台需要输出用户信息_Java_Arrays_Eclipse_Console_Output - Fatal编程技术网

Java 控制台需要输出用户信息

Java 控制台需要输出用户信息,java,arrays,eclipse,console,output,Java,Arrays,Eclipse,Console,Output,我真的很难执行我试图创建的这个程序。我希望用户能够输入他们想要的尽可能多的信息,并且我的程序能够存储这些信息,直到用户键入“退出”这个词。一旦用户输入这个单词,我希望程序结束并在控制台中列出用户输入的所有内容。我知道我需要使用数组,但我并不擅长使用它们 我已经到了用户可以键入“quit”并且程序将结束的部分,但是我不确定如何让它在控制台中列出所有内容 以下是我得到错误信息的地方: import java.util.Scanner; public class Requirement1B { pub

我真的很难执行我试图创建的这个程序。我希望用户能够输入他们想要的尽可能多的信息,并且我的程序能够存储这些信息,直到用户键入“退出”这个词。一旦用户输入这个单词,我希望程序结束并在控制台中列出用户输入的所有内容。我知道我需要使用数组,但我并不擅长使用它们

我已经到了用户可以键入“quit”并且程序将结束的部分,但是我不确定如何让它在控制台中列出所有内容

以下是我得到错误信息的地方:

import java.util.Scanner;
public class Requirement1B {
public static void main(String[] args) {

Scanner scan = new Scanner (System.in);
String name, entry, exit = "";

System.out.println("Please Enter Your Name");
name = scan.nextLine();
System.out.println("Players Name: " + name);

while (true) {

    Scanner scan1 = new Scanner(System.in);
    System.out.println("Please Enter a Game Name, time spent playing the game(in Minutes) and your points"
            + " in this format...\t Game:Time:Points" ); 
    entry = scan.nextLine(); //this is the information I want show on the console once "quit"

    Scanner scan2 = new Scanner (System.in);
    System.out.println("If You Are Done type \"quit\" if not press return");
    exit = scan.nextLine();

    if (exit.equals("quit")) {
        break;
    } // This Works. but doesn't show information.

}
我希望在控制台中显示信息的示例如下:

“用户名”,例如
StackOverflow

“-------------------------------------”

“游戏:时间:点数”例如“COD:120:12345”

“比赛:时间:积分”如“国际足联:120:12345”

“游戏:时间:点数”例如“GTA:120:12345”

“游戏:时间:点数”例如“地雷船:120:12345”


提前感谢您的帮助。

您需要的数据结构是一个列表:

List<String> games = new ArrayList<>();
String game;
Scanner in = new Scanner(System.in);
while ((game = in.nextLine()) != null) {
  if (game.equals("quit")) {
    // process 'games' however you want, for example
    for (String g : games) {
      System.out.println(g);
    }
  } else {
    games.add(game);
  }
}
List games=new ArrayList();
弦乐游戏;
扫描仪输入=新扫描仪(系统输入);
while((game=in.nextLine())!=null){
如果(游戏相等(“退出”)){
//例如,按照您的意愿处理“游戏”
用于(字符串g:游戏){
系统输出打印ln(g);
}
}否则{
games.add(游戏);
}
}

谢谢!这帮了大忙,我真的很感激。谢谢@拉法埃莱
    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String line = "";
    String exit = "";
    boolean isInput = true;
    StringBuilder sb = new StringBuilder();
    System.out.println("Please Enter a Game Name, time spent playing the game(in Minutes) and your points"
            + " in this format...\t Game:Time:Points");
    System.out.println("If You Are Done type \"quit\" if not press return");

    while (isInput) {
        line = scan.nextLine();
        sb.append(line);
        if (line.equalsIgnoreCase("quit")) {
            isInput = false;
        }
    }
    System.out.println("Your String : " + sb.toString());
}
/*
 * Please Enter a Game Name, time spent playing the game(in Minutes) and
 * your points in this format...    Game:Time:Points If You Are Done type
 * "quit" if not press return Output : Game1: Points Game2: Points2 quit
 * Your String : Game1: PointsGame2: Points2 quit exit loop
 */