dorrenchen
发贴: 298
积分: 30
|
于 2003-11-01 07:53
no time to compile it. but this gives you the general idea.
<code> /** * For a given dollar amount, this class calculate all sum combinations * by using $10, $5, and $1 bills. */ public class Bills{
public static void main(String args[]){ if(args.length == 0){ System.out.println("enter a dollar amount."); return; }
int total = args[0]; for(int i=0; i <= total/10; i++){ for(int j=0; j<=total - i*10; j++){ for(int k=0; k<= total - i*10 - j*5; k++){ if(i*10 + j*5 + k == total) System.out.println(i + "*10 + " + j + "*5 +" + k + " = " + total); } } } }//end main
} </code>
|