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. import java.util.stream.Collectors ;
  7.  
  8. import java.time.* ;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. System.out.println( "Bonjour. " + Instant.now() );
  16.  
  17. NatoConverter natoConverter = new NatoConverter();
  18. List < String > result = natoConverter.convert( "Basil" );
  19. System.out.println( result );
  20. }
  21. }
  22.  
  23. class NatoConverter {
  24. private static List < String > natoWords = List.of( "Alpha" , "Bravo" , "Charlie" , "Delta" , "Echo" , "Foxtrot" , "Golf" , "Hotel" , "India" , "Juliett" , "Kilo" , "Lima" , "Mike" , "November" , "Oscar" , "Papa" , "Quebec" , "Romeo" , "Sierra" , "Tango" , "Uniform" , "Victor" , "Whiskey" , "Xray" , "Yankee" , "Zulu" );
  25.  
  26. public List < String > convert ( String input ) {
  27. return List.copyOf(
  28. input
  29. .codePoints()
  30. .mapToObj( this :: wordForCodePoint )
  31. .collect( Collectors.toList () )
  32. );
  33. }
  34.  
  35. public String wordForCodePoint ( int codePoint ) {
  36. if ( codePoint >= 65 && codePoint <= 90 ) { // US-ASCII for A-Z (uppercase) characters are code points 65 to 90.
  37. return NatoConverter.natoWords.get( codePoint - 65 ); // Annoying zero-based index counting.
  38. } else if ( codePoint >= 97 && codePoint <= 122 ) { // US-ASCII for a-z (lowercase) characters are code points 97 to 122.
  39. return NatoConverter.natoWords.get( codePoint - 97 ); // Annoying zero-based index counting.
  40. } else {
  41. return "INVALID CODE POINT: " + codePoint;
  42. }
  43. }
  44. }
Success #stdin #stdout 0.11s 55480KB
stdin
Standard input is empty
stdout
Bonjour. 2021-07-24T20:39:59.052130Z
[Bravo, Alpha, Sierra, India, Lima]