hc学习平台

 找回密码
 立即注册
搜索
热搜: 活动 交友 javakc
 › 永远在下雨 › 日志

拆分数字   

2022-08-06 11:55:33 查看(2) 回复(0)

 

写一个程序,要求输入一个数字,数字中包含5个数位。把数字分解成单独的数位,并打印每一个数位。例如,假定用于键入43263这个数字,那么程序应打印结果:4 3 2 6 3

Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个数字: ");
        int n=scan.nextInt();
        //从后往前取
        String s="";
        while (n>0){
            int y=n%10;
            s=y+" "+s;
            n=n/10;
        }
        System.out.println(s);

评论 (0 个评论)

facelist

全部作者的其他最新日志



站点统计|举报|Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, , Processed in 0.195171 second(s), 9 queries .

Powered by javakc! X1.0

© 2004-2014 javakc

f1208.com 备案号:京ICP备14030918号-1

返回顶部