casting for eg:char a=(int) 100;

解决方案 »

  1.   

    将char强制转换为string,然后再Integer。parseInt。
      

  2.   

    int b='a';//b=97
    得到a的二进制代码97
      

  3.   

    看看下面的测试程序,挺有意思:)
    但愿对你理解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);
    }
    }
      

  4.   

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