How to get upto 20 more names of people as input if user wants to add more names or stop and store them in the list? Thank you | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to get upto 20 more names of people as input if user wants to add more names or stop and store them in the list? Thank you

import java.util.*; class simple { public static void main(String args[]) { ArrayList<String> al=new ArrayList<String>(); Scanner ac=new Scanner(System.in); al.add(ac.next()); Iterator itr=al.iterator(); while(itr.hasNext()) { System.out.println(itr.next()); } } }

25th Sep 2019, 10:04 PM
Abdul Hamid Durrani
Abdul Hamid Durrani - avatar
1 Answer
0
Scanner sc=new Scanner (System.in); ArrayList<String> al=new ArrayList<String>(); while(sc.hasNext()) al.add(sc.next()); System.out.println(al);
4th Nov 2019, 3:25 PM
Jayakrishna 🇮🇳