fork(11) 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.ArrayList;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. public class Main {
  10.  
  11. /**
  12.   * @param args the command line arguments
  13.   */
  14. static ArrayList list;
  15.  
  16. public static void main(String[] args) {
  17. // TODO code application logic here
  18. Main nm = new Main();
  19. nm.list = new ArrayList();
  20. /*
  21.   for(int i=1; i<= 4; i++) {
  22.   list.add(i);
  23.   }
  24.  
  25.   list.remove(list.indexOf(1));
  26.  
  27.   for(int i=0; i<= 2; i++) {
  28.   System.out.print(list.get(i));
  29.   }
  30.   */
  31. nm.test1();
  32. }
  33.  
  34. public void test1() {
  35. for(int i=1; i<= 4; i++) {
  36. if(!list.contains(i)) {
  37. list.add(i);
  38. test1();
  39. list.remove(list.indexOf(i));
  40. }
  41. }
  42. if(list.size() == 4)
  43. {
  44. for(int i=0; i< 4; i++) {
  45. System.out.print(list.get(i));
  46. }
  47. System.out.println("");
  48. }
  49. }
  50. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321