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("");
}
}