fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int limit = 5 ;
  13. List< String > characters = new ArrayList <>() ;
  14. Scanner sc = new Scanner(System.in);
  15.  
  16. String input;
  17. int codePoint;
  18.  
  19. for ( int i = 0 ; i < limit ; i++ ) {
  20. input = sc.next();
  21. int[] codePoints = input.codePoints().toArray() ;
  22. if ( codePoints.length == 1 ) {
  23. codePoint = codePoints[ 0 ] ;
  24. System.out.println( "for index " + i + " the input character is: " + Character.toString( codePoint ) );
  25. characters.add( Character.toString( codePoint ) ) ;
  26. System.out.println("so we get the current result " + characters );
  27. } else {
  28. System.out.println( "Enter just one character." );
  29. break;
  30. }
  31. }
  32. System.out.println( "Done: " + characters ) ;
  33. }
  34. }
Success #stdin #stdout 0.26s 55548KB
stdin
H
😷
l
l
o
stdout
for index 0 the input character is: H
so we get the current result [H]
for index 1 the input character is: 😷
so we get the current result [H, 😷]
for index 2 the input character is: l
so we get the current result [H, 😷, l]
for index 3 the input character is: l
so we get the current result [H, 😷, l, l]
for index 4 the input character is: o
so we get the current result [H, 😷, l, l, o]
Done: [H, 😷, l, l, o]