package ext;
import java.text.DecimalFormat;
import java.util.*;
/*
* 关于小数点保留位数输出
* double a = 1.23456;
String b = new Double(a).toString();
System.out.println(b.substring(b.lastIndexOf(".")+1,5));
b.substring(b.lastIndexOf(".")+1,5)从最后一个.的索引+1开始取,取到b的第5位
import java.text.DecimalFormat;
public static void main(String[] argu){
double d=0.11111;
DecimalFormat dFormat=new DecimalFormat("#.00");
System.out.printl(dFormat.format(d));
}
*
*/
public class Text3 {
static final int MAX=9;
static final int [] parvalue={10000 ,5000 , 2000,1000 ,500 ,100 , 50, 20, 10 };
static final int []num=new int [MAX];
public static void main(String[]args){
int i,j;
Double m;
System.out.println("请输入要找零的金额:");
Scanner in=new Scanner(System.in);
m=Double.valueOf(in.next().trim());
change((int)(m*100));
System.out.println(new DecimalFormat("#.00").format(m)+"要找零的 ");
for(i=0 ;i<MAX ;i++ ){
if (num>0){
System.out.print(new DecimalFormat("#.00").format(parvalue/100.000) +"的"+num+"张 ");
System.out.println();
}
}
}
public static void change(int n){
int i,j;
for(i=0;i<MAX;i++){
if (n>parvalue)break;
}
//System.out.println(parvalue);
while (n>0 && i<MAX){
if(n>=parvalue){
n-=parvalue;
num++;
}
else if (n<10 && n>=5){
num[MAX-1]++;break;
}
else i++;
}
return ;
}
}
|