public class UnicodeTable {
public static void main(String[] args) {
//declarations
int count;
final char Per_Line = 5;
//instantaition
count = 0;
for (int i = 0; i <256; i++ ){
System.out.println( (char)i );
++count;
}
}
}
所以我创建了一个打印所有字符的for循环。我想每行打印五个数字/字符对,每一对用制表符分隔,它们的数字表示也是如此(00065 A 00066 B 00067 C 00068 D 00069 E)。所以我打印所有这些,但我只需要每行5个。那么我会用mod等于0吗?
做一个if语句答案 0 :(得分:4)
使用十进制格式格式化数字,使用&#34; \ t&#34;打印出标签字符。
public class UnicodeTable {
public static void main(String[] args) {
final char Per_Line = 5;
DecimalFormat format = new DecimalFormat("00000"); // format for the number
for (int i = 0; i < 256; i++) {
System.out.print(format.format(i) + "\t" + (char) i + "\t");// print a pair of number and its corresponding ascii character
if ((i + 1) % Per_Line == 0) System.out.println();// change to a new line after printing five pairs
}
}
}
示例输出:
答案 1 :(得分:0)
那会有用。类似的东西:
if((i + 1) % 5 == 0)
{System.out.print("\n");}
答案 2 :(得分:0)
for (int i = 0; i <256; i++ ){
System.out.print( i + "\t" + (char)i + "\t");
if(i % 5 == 0)
System.out.println();
++count;
}
这将对字符进行编号并在它们之间插入标签。每行5个字符。 \t
是一个标签。
答案 3 :(得分:0)
此程序可让您从char
到int
00035 #
和00256 Ā
个帖子
public static void main(String[] args) {
//declarations
int count;
final char Per_Line = 5;
//instantaition
count = 0;
for (int i = 35; i < 257; i++) {
if (countOf(i) == 2) {
System.out.print("000" + i + "\t" + (char) i + "\t");
if (i % 5 == 4) {
System.out.println();
}
} else {
System.out.print("00" + i + "\t" + (char) i + "\t");
if (i % 5 == 4) {
System.out.println();
}
}
++count;
}
}
//returns lengthof int
static int countOf(int value) {
int count = 0;
while (value != 0) {
value = value / 10;
count++;
}
return count;
}