如何将一串数字转化为对应的汉字,
如“123456”转化为“一二三四五六”
谢谢各们帮忙

解决方案 »

  1.   

    if(1)   一
    if(2)   二
      

  2.   

    public class Test {
      String[] s = {
          "零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};  public Test() {
        String str = "20050623";
        String str_ = "";
        char[] temp = str.toCharArray();
        for (int i = 0; i < temp.length; i++) {
          str_ = str_ + s[Integer.parseInt(temp[i] + "")];
        }
        System.out.println(str_);
      }  public static void main(String[] args) {
        new Test();
      }
    }
      

  3.   

    先谢谢大家,
    可能我没说清楚,
    我的意思是,如果有两个TextField
    第一个里由我们自己随便输入一串数字,
    然后再转化为对应的一串汉字,
    再在第二个里面显示出来。
      

  4.   

    import javax.swing.*;
    import java.awt.event.*;public class Test extends JFrame {
      private JPanel pane = null;
      private JTextField text_1 = null;
      private JTextField text_2 = null;
      private JButton button = null;
      private String[] s = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};  public Test() {
        pane = new JPanel();
        text_1 = new JTextField(20);
        text_2 = new JTextField(20);
        button = new JButton("转换");
        button.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e) {
            String str = "";
            String t_1 = text_1.getText();
            char[] temp = t_1.toCharArray();
            for (int i = 0; i < temp.length; i++) {
              str = str + s[Integer.parseInt(temp[i] + "")];
            }
            text_2.setText(str);
          }
        });
        pane.add(text_1);
        pane.add(button);
        pane.add(text_2);
        this.getContentPane().add(pane);
        this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
        this.setSize(260, 130);
        this.setVisible(true);
      }  public static void main(String[] args) {
        new Test();
      }
    }