[英]Printing ASCII table java
这是我的整个程序代码的ASCII表打印部分。 我提示用户输入所需的角色和列,但无法将用户输入连接到表的实际生产。 我知道我的变量匹配不正确,如何更改变量,以便在表的实现中使用rs,re,cs,ce? 我很困惑自己,所以我想在这里寻求帮助。 谢谢!
else if(input == 3)
{
System.out.println("Table B.1 ASCII Character Set, p.741 of textbook");
System.out.println("What is starting row (0-12): ");
int rs = keyboard.nextInt();
System.out.println("What is end row (0-12): ");
int re = keyboard.nextInt();
System.out.println("What is start col (0-9): ");
int cs = keyboard.nextInt();
System.out.println("What is end col (0-9)");
int ce = keyboard.nextInt();
if (rs<0 || rs>12)
{
System.out.println( "Must be int between (0-12)");
rs = keyboard.nextInt();
if (!keyboard.hasNextInt())
{
System.out.println("Must be int between (0-12)");
keyboard.nextInt();
}
}
if (re<0 || re>12)
{
System.out.println( "Must be int between (0-12)");
re = keyboard.nextInt();
if (!keyboard.hasNextInt())
{
System.out.println("Must be int between (0-12)");
keyboard.nextInt();
}
}
if (cs<0 || cs>9)
{
System.out.println( "Must be int between (0-9)");
cs = keyboard.nextInt();
if (!keyboard.hasNextInt())
{
System.out.println("Must be int between (0-9)");
keyboard.nextInt();
}
}
if (ce<0 || ce>9)
{
System.out.println( "Must be int between (0-9)");
ce = keyboard.nextInt();
if (!keyboard.hasNextInt())
{
System.out.println("Must be int between (0-9)");
keyboard.nextInt();
}
}
keyboard.next();
char hex;
char ascii = 0*20;
int row = 2;
int column;
System.out.print("\n\n");
System.out.print(" ");
System.out.println("ASCII Table");
System.out.print(" ");
System.out.print("\n ");
for (hex = '0'; hex<= '9'; hex++)
System.out.print(" " + hex);
for (hex = 'A'; hex<= 'F'; hex++)
System.out.print(" " + hex);
System.out.println("\n");
while (ascii < 0*80)
{
System.out.print(" " + row);
for (column = 0; column < 16; column++)
{
System.out.print(" " + ascii);
ascii++;
}
System.out.print("\n\n");
row++;
}
}
这条线
keyboard.next();
在没有提示的情况下要求输入,并且直到输入内容后ASCII表才出现。 您可以安全地删除它。
未正确指定底部的十六进制文字。 0*20
是零乘以二十,而不是十六进制文字。 十六进制文字是零,后跟字母x
,例如0x20
。 将两个十六进制文字分别从0*20
和0*80
更改为0x20
和0x80
。
通过这些更改,我得到以下输出:
Table B.1 ASCII Character Set, p.741 of textbook
What is starting row (0-12):
0
What is end row (0-12):
12
What is start col (0-9):
0
What is end col (0-9)
9
ASCII Table
0 1 2 3 4 5 6 7 8 9 A B C D E F
2 ! " # $ % & ' ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ^ _
6 ` a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ~
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.