public class 求字符对应的ASCII值 {
public static void main(String arg[]) {
/*
0-9 :对应Ascii 48-57
A-Z :65-90
a-z :97-122
*/
char c1 ='a';
byte b1 =(byte)c1;
System.out.println("a对应的ASCII:"+b1);//97
// 直接将这个字符转化为int型就可以得到ascii码值
char c2 = 'A';
int b2 = c2; //字符的ascii码值
System.out.println("A对应的ASCII::"+b2);//65
//同理将一个ascii码转换为相应的字符:
//例如:字符a
int d =97;
char e = (char)d;
//求出字符串的ASCII值和
String str="hello";
byte[] bytestr = str.getBytes();
int sum = 0;
for(int i = 0; i < bytestr.length; i++){
sum += bytestr[i];
}
System.out.println("hello字符串的ASCII值和:"+sum);//532
}
}
08-05
333
06-17
3061