java中的数组列表用户输入

发布于 2024-10-07 13:49:19 字数 763 浏览 6 评论 0原文

可能的重复:
用于存储用户输入的java arraylist

嗨,使用java中的代码我如何添加一个选项询问用户是否要放入另一个目录,如果不想则打印所有目录。

import java.util.ArrayList;
import java.util.Scanner;

public class Aaa 
{
    public static void main(String[] args) 
{

    ArrayList<String> name = new ArrayList<String>();
    ArrayList<Integer> phone = new ArrayList<Integer>(); 
    Scanner sc = new Scanner(System.in); 
    while (true) 
    {
    System.out.println("Please enter your name: ");
    name.add(sc.next());
    System.out.println("Please enter your number: ");
    phone.add(sc.nextInt());
    }
}

} 

Possible Duplicate:
java arraylist to store userinput

Hi using the code in java how would I add an option of asking the user if they want to put another directory in or not and if not to print all the directories out.

import java.util.ArrayList;
import java.util.Scanner;

public class Aaa 
{
    public static void main(String[] args) 
{

    ArrayList<String> name = new ArrayList<String>();
    ArrayList<Integer> phone = new ArrayList<Integer>(); 
    Scanner sc = new Scanner(System.in); 
    while (true) 
    {
    System.out.println("Please enter your name: ");
    name.add(sc.next());
    System.out.println("Please enter your number: ");
    phone.add(sc.nextInt());
    }
}

} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

征﹌骨岁月お 2024-10-14 13:49:19

如果你想与用户交互,你必须遵循以下步骤:

1)打印一个问题

2)扫描答案

3)分析答案如下:

if (answer.equals("yes"))
    System.out.println("Enter ... informations : ");
else
    System.out.println("Bye");

4)然后进行治疗

Anhuin

if you want to interact with the user, you must follow these steps :

1) Print a question

2) Scan the answer

3) Analyse the answer like :

if (answer.equals("yes"))
    System.out.println("Enter ... informations : ");
else
    System.out.println("Bye");

4) Then do your treatment

Anhuin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文