日期:2014-05-20  浏览次数:20713 次

请教:如何知道一个字符的ASC码
比如如何知道‘a’的asc码,本人初学者,望大家帮忙

------解决方案--------------------
package com.newsclan.udq;

public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
byte a[]= "a ".getBytes();
System.out.println(a[0]);

}

}

------解决方案--------------------
public class c
{
public static void main(String [] args)
{
System.out.println((int) '\n ');
System.out.println((int) ' ');
System.out.println((int) 'a ');
}
}


结果 10 32 97
------解决方案--------------------
private static String getASCIICode(String normalStr) {
StringBuffer buffer = new StringBuffer();
byte[] bitArray = normalStr.getBytes();
int length = bitArray .length;
for (int i = 0; i < length; i++)
{
buffer.append(Integer.toHexString(bitArray [i]));
}
return (new String(buffer));
}
//仅限英文字符串

给分! 给分! 呵呵
------解决方案--------------------
System.in.read()方法返回一个int
这个int就是输入字符的ASC码……