Java字符(char: ‘0’-‘9’)转整型(int)

一.字符转整型

    public void charToInt() {
        for (char a = '0'; a <= '5'; a++) {
            System.out.print(a - '0');
            System.out.print(", ");
        }
        /*
        *0, 1, 2, 3, 4, 5,  */
    }

二.整型转字符(两种)

  public void intToChar1(){
        /*
        * 只能转换0-9,其他数字为字符串的转换*/
        for(int i=0;i<10;i++){
            System.out.print((char)(i+48));
            System.out.print(", ");
        }
        /*0, 1, 2, 3, 4, 5, 6, 7, 8, 9,*/
    }
   public void intToChar2(){
        for(int i=0;i<10;i++){
            System.out.print(String.valueOf(i).charAt(0));
            System.out.print(", ");
        }
        /*0, 1, 2, 3, 4, 5, 6, 7, 8, 9,*/
    }

 

0