最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Java根据正整数的位数并逆序打印出各位数字
时间:2022-06-29 01:37:23 编辑:袖梨 来源:一聚教程网
题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
程序设计:
代码如下 | 复制代码 |
importjava.util.Scanner; publicclassEx24 { publicstaticvoidmain(String[] args) { Ex24 tn =newEx24(); Scanner s =newScanner(System.in); longa = s.nextLong(); if(a<0|| a="">100000) { System.out.println("Error Input, please run this program Again"); System.exit(0); } if(a >=0&& a <=9) { System.out.println( a +"是一位数"); System.out.println("按逆序输出是"+'n'+ a); }elseif(a >=10&& a <=99) { System.out.println(a +"是二位数"); System.out.println("按逆序输出是"); tn.converse(a); }elseif(a >=100&& a <=999) { System.out.println(a +"是三位数"); System.out.println("按逆序输出是"); tn.converse(a); }elseif(a >=1000&& a <=9999) { System.out.println(a +"是四位数"); System.out.println("按逆序输出是"); tn.converse(a); }elseif(a >=10000&& a <=99999) { System.out.println(a +"是五位数"); System.out.println("按逆序输出是"); tn.converse(a); } } publicvoidconverse(longl) { String s = Long.toString(l); char[] ch = s.toCharArray(); for(inti=ch.length-1; i>=0; i--) { System.out.print(ch[i]); } } } |
相关文章
- 火影忍者怎么获得大招 05-03
- 星际战甲新手什么刀好 05-03
- 文明6秦始皇金字塔怎么加速 05-03
- 全民奇迹2龙骸巨剑怎么获得 05-03
- 星露谷物语鲟鱼怎么获得 05-03
- 长安幻想怎么转职 05-03