0

How to type unknown number of char element here(short program)

public static GPA() { int grades; int numgrades=0; char i; ArrayList<Character> niz= new ArrayList<Character>(); Scanner s=new Scanner(System.in); System.out.println("add char"); (HOW TO ADD CHAR ARRAY) }

7th Apr 2020, 10:40 PM
Dzondzula
Dzondzula - avatar
2 ответов
0
while((i=s.next().charAt(0))<0 ){ niz.add(i); System.out.println(niz); CAN I USE THIS?
8th Apr 2020, 12:22 AM
Dzondzula
Dzondzula - avatar
0
there is problem how to stop input of chars //this reads separate char<enter> and ends if user enters empty line String str; while( ! (str = s.nextLine()).isEmpty() ) niz.add(str.charAt(0)); // or you can get it as one String<enter> for (char c: s.nextLine() .toCharArray() ) niz.add(c);
8th Apr 2020, 6:59 AM
zemiak