package com.test; import java.util.Scanner; public class Chinese1 { private static String change(int n) {// 数字转换成汉字表示 String[] c = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; String ss = n + "";//把输入的内容转换成String类型字符串 StringBuilder builder = new StringBuilder(""); int j; for (int i = 0; i < ss.length(); i++) { for (j = 0; j <= 9; j++) {// 遍历ss字符串中每个字符并追加到builder中 if (ss.charAt(i) == j + '0') { break; } } builder.append(c[j]);//往builder对象中追加获取的字符 } return builder.toString();//返回该字符串} public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入int类型的整数:"); int n = sc.nextInt();//键盘获取数值 sc.close(); System.out.println("对应的汉字大写:" + change(n)); } }
小测试一枚,学习java。。。。