关于换钱问题

  • Post author:
  • Post category:其他


//将5元的人民币兑换成1元,5角和1角的硬币,共有多少种不同的兑换方法?

public static void main(String[] args) {
		// TODO Auto-generated method stub
		int s=0;
		for (int i = 0; i <= 5; i++) {
			for (int j = 0; j <= 25; j++) {
				for (int p = 0; p <=50; p++) {
					if (i+j*0.5+p*0.10==5) {
						System.out.println("1元:"+i);
						System.out.println("5角:"+j);
						System.out.println("1角:"+p);
						System.out.println("----------");
						s++;
					} 
				}
			}
			
		}System.out.println(s);
	}

}



版权声明:本文为bjyxszd1585原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。