【程序24】 题目:给一个不多于5位的正整数,要求: 一、求它是几位数,二、逆序打印出各位数字。

/*
	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]+" ");
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值