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. String input = "hello how are you";
  13. List<String> pairs = new ArrayList<>();
  14. for (int i = 0; i < input.length(); ++i) {
  15. // Skip over non-alphabetic characters.
  16. if (!Character.isAlphabetic(input.charAt(i))) continue;
  17.  
  18. // Look for the next alphabetic character:
  19. for (int j = i + 1; j < input.length(); ++j) {
  20. // Skip over non-alphabetic characters.
  21. if (!Character.isAlphabetic(input.charAt(j))) continue;
  22.  
  23. // You've now found a pair.
  24. pairs.add("" + input.charAt(i) + input.charAt(j));
  25. break;
  26. }
  27. }
  28. System.out.println(pairs);
  29. }
  30. }
Success #stdin #stdout 0.14s 35868KB
stdin
Standard input is empty
stdout
[he, el, ll, lo, oh, ho, ow, wa, ar, re, ey, yo, ou]