开发者

arraylist userinput in java [duplicate]

This question already has answers here: Closed 12 years ago.

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());
    }
}

} 


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜