美文网首页
Variable Name & Type

Variable Name & Type

作者: LinKuriboh | 来源:发表于2019-02-14 13:32 被阅读0次

    Naming in AJCG

    • Start with letter, end with letter or digit
    • Only digit ,letter and '_' can be used
    • Name should be meaningful
    • Use Camel-Case

    Type

    Integer Size Range
    byte 1 byte(8 bit) 0 - 255
    short 2 byte(16 bit)0 - 65535
    int 4 byte(32 bit) 0 - 2^32 - 1
    long 8 byte(64 bit) 0 - 2^64- 1
    Float Size Range
    float 4 byte(32 bit) -3.4 * 10^38 - 3.4 * 10^38
    double 8 byte(64 bit) 10^308
    Boolean Size Range
    boolean True False
    Character Size Range
    char 2 byte(16bit) true false

    How to define a variable

    • We must use:

    1.F to tell it's a float type value(not double)
    2.L to tell it's a long type value
    3.If we need to initial a character variable, we can use '\0'

    class Demo2 {
        public static void main(String[] args) {
            /*
            Define Variable
            */
            
            /*Integer*/
            byte byteNumber = 10;
            short shortNumber = 20;
            int intNumber = 30;
            long longNumber = 40L; //L means 40 is a long type
            
            System.out.println("Value of byte type:" + byteNumber);
            System.out.println("Value of short type:" + shortNumber);
            System.out.println("Value of int type:" + intNumber);
            System.out.println("Value of long type:" + longNumber);
            
            /*Float*/
            float floatNumber = 3.14F;  //We must use F to tell it's a float type value
            double doubleNumber = 3.14;
            System.out.println("Value of float type:" + floatNumber);
            System.out.println("Value of double type:" + doubleNumber);
            
            /*Boolean*/
            boolean ret = false;
            System.out.println("Value of boolean type:" + ret);
            
            /*Character*/
            char ch = 'T';
            System.out.println("Value of char type:" + ch);
        }
    }
    

    相关文章

      网友评论

          本文标题:Variable Name & Type

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