设计一个程序,将给定的钱数分成较小的货币单位,要求用户输入一个double型的值,该值为用元角分表示,然后输出一个和总数等价的数量的元角分,(如12.34的输出是You amount 12.34 consists of :12 yuan,3jiao,4fen)用java怎么写代码
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Double d = scan.nextDouble();
String s = String.valueOf(d);
System.out.printf("You amount %.2f consists of : %s yuan,%s jiao,%s fen",d,s.split("\\.")[0],
s.split("\\.")[1].charAt(0),s.split("\\.")[1].charAt(1));
scan.close();
}