|
我写了一个a2c.java的代码
以为是刚学,所以很多东西都很不明白~~~希望大家指点下
- import javax.swing.*;
- import java.util.*;
- public class a2c
- {
- public static void main(String[] args)
- {
- int l;
- char[][] num = new char[3][4] ;
- char[] snum ;
- char[] ch = {"0","1","2","3","4","5","6","7","8","9"};
- char[] ch1 = {"","十","百","千"};
- char[] ch2 = {"元","万","亿"};
- String input = JOptionPane.showInputDialog
- ("qing shu ru yi ge shu zi");
- double k = Integer.parseInt(input);
- long y =(long)k;
- double m =k-y;
- long x = (long)(m*100+0.5);
- for(int i =0;i<3;i++)
- { for(int j =0;j<4;j++)
- {
- num[i][j]=(char)(y%10);
- n/=10;
- }
- }
- for (int t =0;t<2;t++)
- {
- snum[t]=(char)(x%10);
- x/=10;
- }
- for(i=2;i>=0;i--)
- {
- int g=0;
- for(j=3;j>=0;j--)
- {
- if(num[i][j]==0)
- {
- l=1;
- }else{
- if(l!=0){
- System.out.println("ling");
- l=0;
- }
- System.out.println(ch[(int)num[i][j]]);
- System.out.println(ch1[j-1]);
- g=1;
- }
- }
- j=3;
- if(g!=0){
- System.out.println(ch2[i]);
- }
- }
- if(g==0) System.out.println("yuan");
- if((int)snum[0]+(int)snum[1]>0){
- if((int)snum[1]>0) System.out.println(ch[(int)snum[1]]+"fen");
- else System.out.println("ling");
- if((int)snum[0]>0) System.out.println(ch[(int)snum[0]]+"jiao");
- }
- System.out.println("\n");
- }
- }
复制代码 |
|