2020-03-15 |

char

char数据类型是一个单一的16位Unicode字符。char是单个字符。

  • 值:' u0000'(或0)到' uffff'65535
// Java program to demonstrate primitive data types in Java
class GeeksforGeeks
{
    public static void main(String args[]) 
    {
        // declaring character
         char a = 'G';
          
        // Integer data type is generally 
        // used for numeric values
        int i=89;
         
        // use byte and short if memory is a constraint 
        byte b = 4;
         
        // this will give error as number is 
        // larger than byte range
        // byte b1 = 7888888955;
         
        short s = 56;
         
        // this will give error as number is 
        // larger than short range
        // short s1 = 87878787878;
         
         
        // by default fraction value is double in java
        double d = 4.355453532;
         
        // for float use 'f' as suffix
        float f = 4.7333434f;
        
        System.out.println("char: " + a); 
        System.out.println("integer: " + i); 
        System.out.println("byte: " + b); 
        System.out.println("short: " + s); 
        System.out.println("float: " + f); 
        System.out.println("double: " + d); 
    }    
}

输出

char: G
integer: 89
byte: 4
short: 56
float: 4.7333436
double: 4.355453532

0

java教程
php教程
php+mysql教程
ThinkPHP教程
MySQL
C语言
css
javascript
Django教程

发表评论

    评价:
    验证码: 点击我更换图片
    最新评论