/*
2017年3月8日9:41:34
java基础50道经典练习题 例24
Athor: ZJY
Purpose:
【程序24】
题目:给一个不多于5位的正整数,要求:
一、求它是几位数,二、逆序打印出各位数字。
*/
public class ProgramNo24_1
{
public static void main(String[] args)
{
int n = Integer.parseInt (args[0]);
System.out.println("该数是: "+n);
int count = 0;
int[] array = new int[5];
do {
array[count] = n%10;
n /= 10;
count++;
}while(0 != n);
System.out.print("它是"+count+"位数,从个位起依次是:");
for (int i=0; i<count; i++)
System.out.print(array[i]+" ");
}
}
/*
2017年3月8日9:41:34
java基础50道经典练习题 例24
Athor: ZJY
Purpose:
*/
public class ProgramNo24_2
{
public static void main(String[] args)
{
int n = Integer.parseInt(args[0]);
int i = 0;
int[] a = new int[5];
do{
a[i] = n%10;
n /= 10;
++i;
}while(n != 0);
System.out.print("这是一个"+i+"位数,从个位起,各位数字依次为:");
for(int j=0; j<i; j++)
System.out.print(a[j]+" ");
}
}