日期:2014-05-20 浏览次数:20896 次
public class Test
{
public static void main(String[] args)
{
int[] arr = {2, 4, 5, 7, 9};
sort(arr, 0, arr.length);
}
public static void sort(int[] arr, int start, int end)
{
if (start == end)
{
int flag = 0;
for (int i = 0; i < arr.length - 2; i++)
{
if ((arr[i] + arr[i + 1] + arr[i + 2]) % 3 == 0)
{
flag++;
}
else
{
flag--;
}
}
if (flag == 3)
{
System.out.println("" + arr[0] + arr[1] + arr[2] + arr[3]
+ arr[4]);
}
}
else
{
for (int i = start; i < end; i++)
{
int temp = arr[start];
arr[start] = arr[i];
arr[i] = temp;
sort(arr, start + 1, end);
arr[i] = arr[start];
arr[start] = temp;
}
}
}
}