面试题

// 公鸡每只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);
		}
	}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值