ArrayList

 MAIN.JAVA:

import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String args[]) {
        //write your code here
        int i=1;
        String ans;
        Scanner sc=new Scanner(System.in);
        List<String> arraylist=new ArrayList<String>();
        do{
        System.out.println("Enter the username "+i);
        String name=sc.nextLine();
        arraylist.add(name);
        i++;
        System.out.println("Do you want to continue?(y/n)");
        ans=sc.nextLine();
        }
        while(ans.equalsIgnoreCase("y"));



       System.out.println("The Names entered are:");
        for(String s:arraylist){
            System.out.println(s);



       }
        
        




    }
}


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.