这是我整个程序代码的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++;
}
}
答案 0 :(得分:1)
这一行
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 { | } ~