美文网首页
Java中 char 类型转 int

Java中 char 类型转 int

作者: SinX竟然被占用了 | 来源:发表于2017-09-12 22:31 被阅读0次
        System.out.println("输出'0'~'9'的所有char类型字符(还是char类型)");
        for(char ch = '0'; ch <= '9'; ch++) {
            System.out.print(ch + " ");
        }
        System.out.println();


        System.out.println("输出'0'~'9'的所有char类型字符的int型字面值(int类型)");
        for(char ch = '0'; ch <= '9'; ch++) {
            System.out.print(Character.getNumericValue(ch) + " ");
        }
        System.out.println();


        System.out.println("输出'0'~'9'的所有char类型字符的ASCII值");
        for(char ch = '0'; ch <= '9'; ch++) {
            System.out.print((int)ch + " ");
        }
        System.out.println();


        System.out.println("输出'A'~'Z'的所有char类型字符");
        for(char ch = 'A'; ch <= 'Z'; ch++) {
            System.out.print(ch + " ");
        }
        System.out.println();


        System.out.println("输出'A'~'Z'的所有char类型字符的ASCII值");
        for(char ch = 'A'; ch <= 'Z'; ch++) {
            System.out.print((int)ch + " ");
        }
        System.out.println();


        System.out.println("输出'a'~'z'的所有char类型字符");
        for(char ch = 'a'; ch <= 'z'; ch++) {
            System.out.print(ch + " ");
        }
        System.out.println();


        System.out.println("输出'a'~'z'的所有char类型字符的ASCII值");
        for(char ch = 'a'; ch <= 'z'; ch++) {
            System.out.print((int)ch + " ");
        }
        System.out.println();
这里写图片描述

相关文章

网友评论

      本文标题:Java中 char 类型转 int

      本文链接:https://www.haomeiwen.com/subject/cbmhsxtx.html