Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  Chinhhop
Language: JAVA
Code:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class Chinhhop {
     public String[] names = {"Anh", "Binh","Quy","Tuy","Duy","Ninh","Nghia","Ly","Thanh","Vu"};
     public boolean[] status = new boolean[10];
     public List<String[]> strings = new ArrayList<String[]>();
     
     public String[] convertToString(int[] arrayIndex){
          int k = arrayIndex.length;
          String[]  begin = new String[k];
          for(int i = 0; i<k ; i++){
               begin[i] = names[arrayIndex[i]-1];
          }
          return begin;
     }
     
     public void Attempt(int i, int[] arr, int k){
          int n = names.length;
          for(int j = 0 ;j<n;j++){
               if(!status[j]){
                    arr[i] = j+1;
                    if(i == k-1){
                         String[] name = convertToString(arr);
                         strings.add(name);
                         System.err.println(Arrays.toString(name));
                    }else{
                         status[j] = true;
                         Attempt(i+1,arr,k);
                         status[j] = false;
                    }
               }
          }
     }
     public static void main(String[] arg){
          int[] arr = new int[2];
          Chinhhop chinhhop = new Chinhhop();
          chinhhop.Attempt(0,arr,2);
          System.err.println(chinhhop.strings.size());
     }
}
Comments: