ASCII转换 [英] ASCII conversion

查看:112
本文介绍了ASCII转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将ASCII值转换为相应的字符,因此我写了这个简单的代码:

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

但是作为输出它没有显示,控制甚至没有走出循环,虽然过程得到完成.plz解释这种行为和正确的代码。

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.

推荐答案

正如其他人已经指出的,你已经包括控制字符;如果你改变循环(如下),你得到完整的集合,不包括这些控制字符:

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

这篇关于ASCII转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆