ASCII conversion

左心房为你撑大大i 提交于 2019-12-10 18:34:00

问题


I wanted to convert ASCII values to its corresponding characters so I wrote this simple code:

public class Test {


    public static void main(String[] args) {
        int i=0;
        char ch='c';    
        for(i=0;i<127;i++)
        {
            ch=(char)i;
            System.out.print(ch+"\t");
        }
        System.out.println("finish");
    }
}

But as output it's showing nothing and along with that the control is not even getting out of the loop though the process gets finished..plz explain this kind of behavior and the right code.


回答1:


As other people have pointed out, you have included the control characters; if you alter the loop (as below) you get the full set, excluding these control characters:

public static void main() {
    for(int i = 33; i < 127; i++)
    {
        char ch = (char) i;
        System.out.print(i + ":" + ch + "\t");
    }
    System.out.println("finish");
}


来源:https://stackoverflow.com/questions/37297869/ascii-conversion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!