arraylist userinput in java [duplicate]
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
精彩评论