fork(1) 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. String input = "0Z9" ; // Simulate FAULTY INPUT.
  13. int[] codePoints = input.codePoints().toArray() ;
  14. int[] numbers = new int[ codePoints.length ] ;
  15. int index = 0 ;
  16. for ( int codePoint : codePoints )
  17. {
  18. String digit = Character.toString ( codePoint ) ;
  19. if ( Character.isDigit ( codePoint ) ) // Verify the code point does indeed represent a character that is a digit.
  20. {
  21. int number = Integer.parseInt ( digit ) ;
  22. numbers [ index ] = number ;
  23. index = index + 1 ;
  24. }
  25. else
  26. {
  27. System.out.println ( "ERROR - Received non-digt. Code point: " + codePoint + ". Character: " + digit ) ;
  28. }
  29. }
  30. System.out.println ( Arrays.toString( numbers ) ) ;
  31. }
  32. }
Success #stdin #stdout 0.2s 56088KB
stdin
Standard input is empty
stdout
ERROR - Received non-digt. Code point: 90. Character: Z
[0, 9, 0]