好吧,也算是学会了一点儿JAVA了。

public class charcode
{
	/* 根据带入的前3个整数参数,列出ASCII码表中,参数1 到 参数2 对应的字符,参数3决定每行显示的个数。*/
	
	public static void main(String[] args )
	{
		char ch;
		char enterch = '\r';
		int defaultStart = 33;
		int defaultEnd = 64;
		int defaultPerline = 8;
		int i, max, interval, perline;
		String strStart, strEnd, strPerline, strHelp;
		String printContent;

		/*验证参数,若没有参数或参数非法则采用默认值*/
		if (args.length>0)
		{
			strStart = args[0];
			strEnd = args[1];
			strPerline = args[2];
			try {
				i = Integer.parseInt(strStart);
				max = Integer.parseInt(strEnd);
				perline = Integer.parseInt(strPerline);
			}
			catch(Exception e) {
				System.out.println("Arg invalid. Use default:" + defaultStart + "-" + defaultEnd + "."); 
				i = defaultStart;
				max = defaultEnd;
				perline = defaultPerline;
			}
		}
		else 
		{
			i = defaultStart;
			max = defaultEnd;
			perline = defaultPerline;
		}
		
		/*列出所有参数*/
		System.out.print("Arg:");
		for (String stringArg : args)
		{
			System.out.print( stringArg + " ");
		}
		System.out.println("");

		/*分行显示,每行perline个*/
		interval = 1;
		for(int count = i ; count <= max ; count++)
		{
			ch = (char)count;
			printContent = count + "  " + ch + "    ";
			System.out.print(printContent);
			if (interval % perline == 0 ) 
			{
				System.out.println(""); 
			}
			interval++;
		}
		System.out.println("");
	}
}

偷笑偷笑

执行结果





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值