繁体   English   中英

如何让程序创建自己的变量以匹配(无限)用户输入?

[英]How do I have a program create its own variables to match (up to an infinite) amount of user inputs?

import java.util.Scanner;

public class Study {

public static void main(String[] args){

    System.out.println("Hello, welcome to Study Help v1.0!");
    try {
        Thread.sleep(2500);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("In this program we will help you study for an upcoming test or assessment!");
    System.out.println("Unfortunately, this version only works for a multiple choice test.");
    try {
        Thread.sleep(2500);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("Please input the number of questions that there will be for your studying.");

    int questions;

    Scanner userNumber = new Scanner (System.in);

    questions = userNumber.nextInt();

    System.out.println("You've chosen " + questions + " questions.");
    System.out.println("Now, add the questions to your study guide.");

    //This will later become a while loop (until their input numbers equal the amount of questions they said earlier)
    System.out.println("Input the full question number " + (questions-=questions-1)+ " now.");

    String userInput;

    Scanner userQuestion = new Scanner (System.in);

    userInput = userQuestion.nextLine();
    }
}

我需要能够将每个单个问题输入分配给新变量(questionOne,questionTwo等)。 我会对答案做同样的事情,并将两者(问题和答案)存储在单独的数组中。

查看Javas ArrayList类型。 您可以在运行时使用list.add(obj);存储许多对象list.add(obj); 方法。 这样,您可以存储尽可能多的问题!

暂无
暂无

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

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