Java 我该如何打印每行5个字符及其数字表示 公共类UnicodeTable{ 公共静态void main(字符串[]args){ //声明 整数计数; 每行的最终字符数=5; //实例化 计数=0; 对于(int i=0;i

Java 我该如何打印每行5个字符及其数字表示 公共类UnicodeTable{ 公共静态void main(字符串[]args){ //声明 整数计数; 每行的最终字符数=5; //实例化 计数=0; 对于(int i=0;i,java,Java,,这将起作用。类似于: 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++ ){

,这将起作用。类似于:

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;
        }
    }

}

使用十进制格式设置数字格式,使用“\t”打印制表符

if((i + 1) % 5 == 0)
{System.out.print("\n");}
公共类UnicodeTable{
公共静态void main(字符串[]args){
每行的最终字符数=5;
DecimalFormat=新的DecimalFormat(“00000”);//数字的格式
对于(int i=0;i<256;i++){
System.out.print(format.format(i)+“\t”+(char)i++“\t”);//打印一对数字及其对应的ascii字符
if((i+1)%Per_Line==0)System.out.println();//打印五对后更改为新行
}
}
}
示例输出:


for(int i=0;i此程序允许您从
00035
00256
获取所有
char
s和
int
s

for (int i = 0; i <256; i++ ){
        System.out.print( i + "\t" + (char)i + "\t");
        if(i % 5 == 0)
            System.out.println();

        ++count;
    }
publicstaticvoidmain(字符串[]args){
//声明
整数计数;
每行的最终字符数=5;
//实例化
计数=0;
对于(int i=35;i<257;i++){
如果(i的计数=2){
系统输出打印(“000”+i++“\t”+(char)i++“\t”);
如果(i%5==4){
System.out.println();
}
}否则{
系统输出打印(“00”+i+“\t”+(char)i+“\t”);
如果(i%5==4){
System.out.println();
}
}
++计数;
}
}
//返回lengthof int
静态int countOf(int值){
整数计数=0;
while(值!=0){
数值=数值/10;
计数++;
}
返回计数;
}

那么我如何打印像这样的字符00066 B,00066 B 00067 C 00068 D,用制表符分开。我想我需要DecimalFormatUp,你会的。有人已经发布了它,但我的看法是:
for(int I=0;I<256;I++){DecimalFormat deformat=new DecimalFormat(“00000”);{System.out.print(deformat(I)+“\t”+(char)i+“\t”);}如果((i+1)%5==0{System.out.print(“\n”);}}
for (int i = 0; i <256; i++ ){
        System.out.print( i + "\t" + (char)i + "\t");
        if(i % 5 == 0)
            System.out.println();

        ++count;
    }
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;
}