public static void main(String[] args) { int[] arr = new int[]{1,2,3,4,5,6,7,8,9}; temp(0,arr,0,0); System.out.println(sum); } static int sum=0; static boolean[] isVisited = new boolean[9]; private static void temp(int index ,int arr[],int count,int cur){ if(count==3){ if(cur%2==0){ sum++; } return; } if(index==arr.length)return; for (int i =index; i < arr.length; i++) { if(isVisited[i])continue; isVisited[i]=true; temp(i+1,arr,count+1,cur+arr[i]); isVisited[i]=false; } }