java程序题:把一元钞票换成一分、二分、五分硬币(每种至少一枚),有哪些种换法

请问一共有多少种?


/**
 * 2015年1月15日下午11:36:48 测试通过,望采纳
 * @author season
 *
 */
public class ChangeMoney {
/**
 * getMethodTotal TODO 获取换取的多少种方法 
 * @param yourMoney 想要换的钱
 * @return int 返回方法总数
 */
public static int getMethodTotal(int yourMoney){
int method = 0;

for(int one =1; one<=98; one++)
for(int two =1; two<=49; two++)
for(int five =1; five <=19; five++)
if(one+two+five==100)
method++;
return method;
}

public static void main(String[] args){
System.out.println("\nThe total is: "+getMethodTotal(1));
}

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-01-15
package count;

public class Count{

public static void main(String[] args) {
int count =0;
int total = 100;
int min = 1 ,max = 5 ,mid = 2;
int sum = total - min - max -mid;
for (int i=0;i<=sum;i++){
for(int j=0;j<=(sum -i)/2;j++){
for(int k=0;k<=(sum-i-2*j)/5;k++){
if(i+2*j+5*k==sum){
count++;
}
}
}
}
System.out.println(count);
}
}
count=461
相似回答