// 公鸡每只5元,母鸡每只3元,小鸡三只1元
int x,y,z;
for (x=0;x<20;x++) {
for (y=0;y<33;y++) {
z=100-x-y;
if ((z%3==0) && (5*x+3*y+z/3==100)) {
System.out.println("m="+x+" g="+y+" x="+z);
}
}
}
// 每只公鸡3元,母鸡4元,小鸡0.5元每只,请问如何100块买100只鸡.
for (int i=0;i<33;i++) {
for (int j=0;j<25;j++) {
int k=100-i-j;
if (3*i+4*j+0.5*k==100 && i+j+k==100) {
System.out.println("g="+i+" m="+j+" x="+k+" z="+(i+j+k));
}
}
}
// 去除数组中的对相等数
int[] array=new int[]{9,-2,10,-7,6,-9,5,8,-2,11};
for (int i=0;i<array.length;i++) {
int tempA=array[i]<0?100+array[i]:100-array[i];
for (int j=i+1;j<array.length;j++) {
int tempB=array[j]<0?100+array[j]:100-array[j];
if (tempA==tempB) {
System.out.println(array[i]+"\t"+array[j]);
}
}
}
// 输出 1234 123 234 12 23 34 1 2 3 4
// 方法1
String str="12345";
for (int i=str.length();i>0;i--) {
for (int j=0;i+j<=str.length();j++) {
System.out.print(str.substring(j,i+j)+"\t");
}
}
// 方法2
String str="12345678";
int temp=1;
private void print(int count) {
if (temp<=str.length()) {
for (int i=0;i<temp;i++) {
System.out.print(str.substring(i,count+i)+"\t");
}
temp++;
count--;
print(count);
}
}