所以我正在制作一个程序,我尝试做的一件事就是打印一个像这样转换后的 ASCII 字符表
DEC HEX OCT DEC HEX OCT DEC HEX OCT DEC HEX OCT
A 65 101 25 C 66 111 232 E 12 32 12 G 21 56 12
B 12 89 23 D 45 124 23 F 34 123 10 H 89 203 8
我已经完成了程序的转换部分我只需要一点帮助让表格以正确的方式打印
有人有什么建议吗?
我的代码
public static void getInputs(String[] args) {
//c1, c2, and c3 are the characters the user enters
//selector is what determends how the method will print
char c1 = args[0].charAt(0);
char c2 = args[1].charAt(0);
char c3 = args[2].charAt(0);
int letter1 = (int) c1;
int letter2 = (int) c2;
String selector = Character.toString(c3);
char[] arr;
int index = 0;
arr = new char[c2 - c1 + 1];
//Yif the selector is the letter h the program will print horizontaly
//Xif the selector is the letter v the program will print vertically
//Yprogram prints horizontaly
//Xprogram prints vertically
//Yselector works
//Xclean up everything
if (letter2 >= letter1){
if (selector.equals("h")) {
//(char)x is the letter
//x is the number
int counter = 0;
for (int x = (int) c1; x <= c2 && counter < 4; ++x) {
System.out.print(" " + "DEC " + "Oct " + "Hex");
++counter;
}
System.out.println("\n");
for (int x = (int) c1; x <= c2; ++x) {
if (counter % 4 == 0) {
System.out.println("");
}
String hex = Integer.toHexString(x);
String oct = Integer.toOctalString(x);
arr[index++] = (char) x;
System.out.print(" " + (char) x + " "
+ x + " " + oct + " " + hex);
++counter;
}
我知道我的代码有点乱,你可以把东西放在方法中,但现在我只专注于让表格正确打印。
我也为我的问题的坏名声道歉。
慕容3067478
哔哔one
慕斯王
相关分类