题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
public class DaoXu {
private int num,r;
public static void main(String[] args) {
new DaoXu().Bijiao();
}
public void Bijiao(){
while(true){
num = (int)(Math.random()*100000);
System.out.print("这个数为:"+num);
if(num==100000){
break;
}else{
if(num/10000!=0){
System.out.print(",是五位数\n");
}else if (num/1000!=0) {
System.out.print(",是四位数\n");
}else if (num/100!=0) {
System.out.print(",是三位数\n");
}else if (num/10!=0) {
System.out.print(",是二位数\n");
}else{
System.out.print(",是一位数\n");
}
System.out.print("此数倒序输出为:");
print();
}
}
}
public void print(){
while(num>0){
r = num%10;
num = num/10;
System.out.print(r);
}
System.out.println();
//关闭程序
System.exit(0);
}
}