java中的数组列表用户输入
可能的重复:
用于存储用户输入的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想与用户交互,你必须遵循以下步骤:
1)打印一个问题
2)扫描答案
3)分析答案如下:
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 :
4) Then do your treatment
Anhuin