A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© EdwardWuang 中级黑马   /  2016-9-19 09:06  /  2695 人查看  /  28 人回复  /   1 人收藏 转载请遵从CC协议 禁止商业使用本文

第一次点招没过,心里塞塞的,有一道题,写一个工具方法,传入一个int整数,将其转化成中文大写,如123,改写为一百二十三,然后将最后的大写返回,现在还是不会做啊,啊啊啊啊,求教各位大神!!!!!!!!!!!!!!!!!!!!!!!!!

28 个回复

倒序浏览
快来一个大神帮帮我
回复 使用道具 举报
这种类型的题,我发了一个贴,有代码,你可以去看看
回复 使用道具 举报
18001105207 发表于 2016-9-19 10:32
这种类型的题,我发了一个贴,有代码,你可以去看看

有具体链接么
回复 使用道具 举报
我也很想知道,百度上的答案貌似不是很好
回复 使用道具 举报
huyuxiong 来自手机 初级黑马 2016-9-19 12:09:28
地板
我也不会,求大神告诉下
回复 使用道具 举报
等下我做做.点招就这样的题呀
回复 使用道具 举报
我是这么做的:
判断数长度,按需要分成3段,一段亿为单位,一段万为单位,一段没单位
再转成中文配单位,1234>>>一千二百三十四,亿段+"亿",万段+"万"
再处理语法,比方说两个零三个零一起的转成一个零.头和尾都不能为零

大体思路是这样,中间的东西自己去实现,各种办法都行..

本来想来装个B的,没想到写了两个多小时啰啰嗦嗦写了130多行代码,汗...


回复 使用道具 举报
1111111111111111111111111111111
回复 使用道具 举报
本帖最后由 431613758 于 2016-9-19 17:42 编辑

import java.util.Scanner;

public class Daxie2 {
        public static void main(String[] args) {
                while (true) {
                        System.out.println("请输入一个大于5小于1000的正整数");
                        int a = new Scanner(System.in).nextInt();
                        if (a < 0 || a > 1000) {
                                System.out.println("超出");
                                continue;
                        }
                        zhuanHuan(a);
        }                               
        }

        public static void zhuanHuan(int a) {
                String[] s={"零","一","二","三","四","五","六","七","八","九"};
                int bai = a / 100;
                int shi = a % 100 / 10;
                int ge = a % 10;
                if (a < 10) {
                        System.out.println(s[ge]);
                }
                if (a >= 10 && a < 100) {
                        if (ge != 0) {
                                System.out.println(s[shi] + "十" + s[ge]);
                        } else {
                                System.out.println(s[shi] + "十");
                        }
                }
                if (a >= 100 && a < 1000) {
                        if (a % 100 / 10 != 0) {
                                if (ge != 0) {
                                        System.out.println(s[bai] + "百" + s[shi] + "十" + s[ge]);
                                } else {
                                        System.out.println(s[bai] + "百" + s[shi] + "十");
                                }
                        }else{
                                if (ge != 0) {
                                        System.out.println(s[bai] + "百" + s[shi] + s[ge]);
                                } else {
                                        System.out.println(s[bai] + "百" );
                                }
                               
                        }
                }
        }
}   }         } }
回复 使用道具 举报
import java.util.Scanner;

/**
*  1.        键盘录入一个大于1小于1000的正整数,将该整数转换成中文在控制台输出
*  2.        除非输入数字不在规定的范围,否则可以一直进行输入转换
            小于10,数字后不需要带单位
                大于9小于100,数字后需要带单位”十”
                大于99小于1000,数字后需要带单位”百”
                数字转换成中文样式如下:
                5        五
                15       一十五
                115      一百一十五
*/
public class Prictice7 {
        public static void main(String[] args) {
                String[] s1 = {"零","一","二","三","四","五","六","七","八","九"};
                String[] s2 = {"十","百"};
                Scanner sc = new Scanner(System.in);
               
                while(true) {
                        System.out.println("请录入一个大于1小于1000的正整数:");
                        int num = sc.nextInt();
                        if(num < 1 || num > 1000) {
                                System.out.println("您的输入不合法! 系统结束");
                                System.exit(0);
                        }
                       
                        if(num < 10) {
                                System.out.println(s1[num]);
                        }
                       
                        if(num > 9 && num < 100) {
                                int s = num/10;
                                int g = num%10;
                                System.out.println(s1[s]+s2[0]+s1[g]);
                        }
                       
                        if(num > 99 && num < 1000) {
                                int b = num/100;
                                // 注: 十位,要除以10,再模10
                                int s = num/10%10;
                                int g = num%10;
                                // 判断如果是整百数,直接输入 ..整
                                if(s==0 && g==0) {
                                        System.out.println(s1[b]+s2[1]+"整");
                                } else {
                                        System.out.println(s1[b]+s2[1]+s1[s]+s2[0]+s1[g]);
                                }
                        }
                }
        }
}
回复 使用道具 举报
厉害,学习到了~
回复 使用道具 举报
gaol 中级黑马 2016-9-19 22:17:44
13#
学习到了,黑马果然大神多啊
回复 使用道具 举报
这么简单!!!
回复 使用道具 举报
看了一下,下面还是有大神的
回复 使用道具 举报
点招都这么难吗
回复 使用道具 举报
定义String类型的数组
回复 使用道具 举报
刚开始,表述示 并不会      
回复 使用道具 举报
还好,我们做的题是把1000以内的数字变成中文,感觉比这个难
回复 使用道具 举报
{:3_50:}这种题碰到了确实就可以等下次了
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 加入黑马