0

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

} 
0

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

3 Comments

fyi: code blocks inside list items need double indentation (8 spaces)
I removed the list items to solve this problem :) But thanks you for the tips !
Thanks for the help it works now :) all I need it doing now is asking after each directory if I want to add another one and if not to print out the arraylist

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.