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.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void createHostArray(String[] root, String[] result, int index) {
  12.  
  13. String host="";
  14. int i = index;
  15. if (index == root.length) {
  16. return;
  17. }
  18. for ( ; i < root.length-1; i++) {
  19.  
  20. host += root[i] + ".";
  21. }
  22. System.out.println(index + "-" + i);
  23. if (i < root.length) {
  24. host += root[i];
  25. }
  26.  
  27. result[index] = host;
  28. createHostArray(root, result, ++index);
  29. }
  30.  
  31. public static void main (String[] args) throws java.lang.Exception
  32. {
  33. String host = "a.b.c.d.e.f";
  34.  
  35. String [] tokens = host.split("\\.");
  36.  
  37. String [] result = new String[tokens.length];
  38.  
  39. createHostArray(tokens, result, 0);
  40.  
  41. for (String s : result) {
  42. System.out.println(s);
  43. }
  44.  
  45. }
  46. }
  47.  
  48.  
  49.  
  50.  
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
0-5
1-5
2-5
3-5
4-5
5-5
a.b.c.d.e.f
b.c.d.e.f
c.d.e.f
d.e.f
e.f
f