Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок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()); } } }
1 ответ
0
Scanner sc=new Scanner (System.in);
ArrayList<String> al=new ArrayList<String>();
while(sc.hasNext())
al.add(sc.next());
System.out.println(al);