ҳ > 򿪷 > > Java >

javaѧϰ֮·֮﷨--ϰ

2016-07-22

javaѧϰ֮·֮﷨--ϰ

/*
intͱֵ
*/
public class VariableTest {

    public static void main(String[] args) {
        //  : ڴеһ鱻,СƵ
        //   ;
        int var1;
        // ʼֵ, 100ֵvar1ָڴռ(д)
        var1 = 100;

        System.out.println(var1); // ӡvar1еֵ

        // ֵͨ
        var1 = 200; // 200ֵдvar1ָıռ

        System.out.println(var1); // ӡvar1еֵ

        // ͳʼֵ
        // 1) ڴпٿռ,Ϊvar2, 2) var1ҵռ,еֵƳ 3) ѸƳֵдvar2ָĿռ
        int var2 = var1; 

        System.out.println(var2);

        int var3 = var1 * var2;

        System.out.println(var3);

    }

}


/*
doubleͱֵ
*/
class VariableTest2 {

    public static void main(String[] args) {
        double d1,d2;
        // гʼֵ
        d1 = 1.234;
        d2 = .832;

        double d3 = d1 * 200; // ٿռ, d1еֵƳ  200г˷, ֵдd3Ŀռ.
        System.out.println(d3);
        d3 = d3 - d2;
        System.out.println(d3);
    }

}


/*
֮໥ת
СΧΧԶת
ΧСΧҪǿת
*/
public class VariableTest { // ļһ

    public static void main(String[] args) {
        byte b1 = (byte)200; // int
        short s1 = 30;
        int i1 = 40;
        long l1 = 50;

        long l2 = 23423432423423l;

        // 丳ֵʱ, ݹϵ, ҪǺ
        //b1 = s1; 
        b1 = (byte)s1;
        s1 = b1;

        s1 = (short)i1;
        i1 = s1;

        i1 = (int)l1;
        l1 = i1;

        float f1 = 3.999999f; // 3.2Ĭdouble
        // ǿת : (Ŀ)Ҫת
        float f2 = (float)3.2; // 3.2Ĭdouble
        double d1 = 9.8;

        //20 = 20; д

        f1 = l1; // ΧıԼݷΧСı
        l1 = (long)f1;

        boolean bl1 = true;
        boolean bl2 = false;
        //bl1 = (boolean)f1;
        bl2 = bl1;
    }

}

/*
charͱֵ
*/
class VariableTest2 { 

    public static void main(String[] args) {
        // charͱбַUnicode
        char ch1 = 'a'; //character
        char ch2 = 'b';
        char ch3 = 'A';
        char ch4 = 'B';
        char ch5 = '';
        char ch6 = '';
        System.out.println((int)ch1); // ӡһַUnicodeֵ
        System.out.println((int)ch2);
        System.out.println((int)ch3);
        System.out.println((int)ch4);
        System.out.println((int)ch5);
        System.out.println((int)ch6);
        int i1 = 25105;
        char ch7 = (char)i1;
        System.out.println(ch7);

        ch2 = (char)(ch2 + 1); // , int
        System.out.println(ch2);
        byte b = 100;
        ch2 = (char)b;

        char ch8 = '\n';
        System.out.println((int)ch8);
        char ch9 = 10;
        System.out.println((int)ch9);
    }

}

// һcharͱ, ͨ ӡ26Сдĸ
// ٴӡ10ַ
class Exer1 {

    public static void main(String[] args) {
        char ch = 'a';
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);

        ch = 48;
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);
        ch = (char)(ch + 1); // ͵, int
        System.out.println(ch);

    }
}


ȵƼ