char 和 int类型的转换

danger1 2003-10-20 03:41:07
char 如何转化为 int类型
...全文
1188 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
dovek2 2003-10-20
  • 打赏
  • 举报
回复
Integer.parseInt
seayou 2003-10-20
  • 打赏
  • 举报
回复
怎么没说运行结果?
网络咖啡 2003-10-20
  • 打赏
  • 举报
回复
public class T3{
public static void main(String[] args){
//第一种转换
int i = 0;
char c = 'a';

i = c;

System.out.println(i);

//第二种转换
int j = 0;
char c1 = '1';

j = Integer.parseInt(Character.toString(c1));

System.out.println(j);
}
}
chinaemin 2003-10-20
  • 打赏
  • 举报
回复
看看下面的测试程序,挺有意思:)
但愿对你理解char与int有帮助!

public class TestCast{
private static final char TEST_CHAR = 'A';
public TestCast(){}
public boolean test(String testVer){
System.out.println (testVer + " is a String!");
return true;
}
public boolean test(int testVer){
System.out.println (testVer + " is a int!");
return true;
}
public boolean test(char testVer){
System.out.println (testVer + " is a char!");
return true;
}
public boolean cast(String testVer){
System.out.println (testVer + " can cast to String!");
return true;
}
public boolean cast(int testVer){
System.out.println (testVer + " can cast to int!");
return true;
}
public static void main(String[] args){
TestCast test = new TestCast();
test.test(TEST_CHAR);
test.test(TEST_CHAR + "");
test.cast(TEST_CHAR);
}
}
vampire1129 2003-10-20
  • 打赏
  • 举报
回复
int b='a';//b=97
得到a的二进制代码97
qiyongjun2003 2003-10-20
  • 打赏
  • 举报
回复
int i=Integer.parseInt(s);
stamp80 2003-10-20
  • 打赏
  • 举报
回复
将char强制转换为string,然后再Integer。parseInt。
nightsuns 2003-10-20
  • 打赏
  • 举报
回复
casting

for eg:

char a=(int) 100;

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧