初学者,用了个笨办法,完全不能与上面那位高手比,求鼓励!
class FuKuan
{ int count = 0;
//int x =0;
public void fukuan(int num)
{
for(;num>=20;)
{
count++;
num = num-20;
}
if(count>0)
System.out.println(count+"个20元");
count = 0;
for(;num>=10;)
{
count++;
num = num-10;
}
if(count>0)
System.out.println(count+"个10元");
count = 0;
for(;num>=5;)
{
count++;
num = num-5;
}
if(count>0)
System.out.println(count+"个5元");
count = 0;
for(;num>=1;)
{
count++;
num = num-1;
}
if(count>0)
System.out.println(count+"个1元");
}
}
class Test2
{
public static void main(String[] args)
{
FuKuan fk = new FuKuan();
fk.fukuan(137);
}
} |