Переменные, типы данных, операторы

  • Published on
    11-Apr-2017

  • View
    39

  • Download
    6

Embed Size (px)

Transcript

  • , , . unguryan@itstep.org

    *

  • . (identifiers); (key words); (literals); (separators); (operators).

    *

  • . Java . , , .

    Cat , cat

    *

  • () Java .

    System.out.println("Hello, world!");

    *

  • main(), , . main . Eclipse , .)

    *

  • ? - , , .

    *

  • , () . , .

    *

  • - .

    *

  • - , .

    *

  • . . java .

    *

  • boolean byte, short, int, long float, double char

    *

  • .byte .

    : 1 . : -128 127

    *

  • .char - ( ).

    : 2 : 0 65535

    *

  • .short . byte.

    : 2 : -32 768 32767

    *

  • .int (4 ) -2 147 483 648 2 147 483 647long (8 ) -9223372036854775808 9 223 372 036 854 775 807float (4 ) - 3. 4-038.. 3. 4+ 038double (8 ) - 1. 7-308.. 1. 7+ 308

    *

  • .boolean true false. boolean JVM.

    *

  • IEEE 754 , . , , (), (0 , 1 ).

    *

  • :(-1)^s M 2^E, s , M , E . , , .

    *

  • double 0 , 0 ( NaN 0.0/0). Double.NEGATIVE_INFINITY Double.POSITIVE_INFINITY, -1.0 / 0.0 1.0 / 0.0 .

    *

  • doubleDouble.MIN_VALUE , double, .

    *

  • - , , $ _. , . Java , .

    *

  • ;int a;short b;char c, d; // char e;

    *

  • c boolean b = true;int a = 4;short b = 10;char c = 3, d = 5;char c = 'F';. Task02

    *

  • byte, short, int, long, float, double, char, booleando, while, for, break, continue if, else, switch, case, default,breakprivate,public, protected, final, static, abstract, synchronized, volatile, strictfp

    *

  • false,true, null, return, void, package, import

    try, catch, finally, throw, throwsnew, extends, implements, class, instanceof, this, super

    *

  • , , . , () final. .

    *

  • , (, , - ).

    *

  • , , null-. Java : (integer); (floating-point); (boolean); (character); (string);null- (null-literal).

    *

  • 2 - int010 - int 0x10 - int 2L - long, l ( )

    *

  • JDK 7 . 0b 0B:int x = 0b1010;

    *

  • JDK 7 :int x = 123_456_789;double num = 8_343_398.0;

    *

  • 2F - float, f2D - double, d1.2 - double

    *

  • 2e5 - double, , e , e, .. 2*10^5 = 200000

    *

  • -1.23e-3 - double, -1.23*10-3 = -0.001232e-2f - float, 0.02

    *

  • s, a.

    Unicode \u0041 A.

    *

  • \b \u0008 backspace BS -\t \u0009 horizontal tab HT -\n \u000a linefeed LF - \f \u000c form feed FF - \r \u000d carriage return CR -

    *

  • \" \u0022 double quote "- \' \u0027 single quote '- \\ \u005c backslash \- \ \u0000 to \u00ff

    *

  • booleanfalse true -

    . Task3

    *

  • , . .

    *

  • , (), [], {}, ;, ,, ..

    *

  • Java ( ), , .

    *

  • , .

    *

  • .

    *

  • , , . , .

    *

  • x= 3;y=x;z=x;

    x1 =x2 =x3 = 0;

    .

    *

  • "-" ; "+" ;

    *

  • "++" 1; "--" 1. "~" ( ) ( 0 1 1 0);

    *

  • "+" "-":inti= 3,j,k;j= -i; //j= -3k= +i;//k= 3 :int a = 15;int b; b = ~a;// b = -16. Task04.java

    *

  • ( , , ..)

    *

  • + - * / % ++ --

    int a = 5 + 5; a = b * c;b++; a = 10 % 2;

    *

  • intx= 7,x1,x2,x3,x4,x5;x1 =x+10; //x1 = 17x2 =x 8; //x2 = -1x3 =x2 *x;//x3 = -7x4 =x / 4;//x4 = 1 ( )x5 =x%4//x5 = 3 ( 7 4). Task05.java

    *

  • == (), != ( ),> (), >= ( ),< ()
  • boolean isEqual, isNonEqual, isGreater,isGreaterOrEqual, isLess, isLessOrEqual;int x1 = 5, x2 = 5, x3 = 3, x4 = 7;isEqual = x1 == x2;// isEqual = trueisNonEqual = x1 != x2;// isNonEqual = falseisGreater = x1 > x3;// isGreater = trueisGreaterOrEqual = x2 >= x3; // isGreaterOrEqual = trueisLess = x3 < x1;// isLess = trueisLessOrEqual = x1
  • () boolean boolean. .

    *

  • "!" falsetrue, ;

    "&" true, , true, false;

    *

  • "|" true, , true, false. "^" true, , , false.

    . Task07.java

    *

  • &

    (AND)&= (AND)

    |

    (OR)|= (OR)

    ^

    (XOR)^=

    (XOR)

    *

  • ||OR

    (shortcircuitOR)== &&AND

    (shortcircuitAND)!= !

    (NOT)? :

    if-then-else

    *

  • [-1] ? [-2] : [-3].

    :

    int x = n > 1 ? 0 : 1;

    x 0, n > 1(n > 1 true) 1, n 1(n > 1 false).

    *

  • Java () :

    = :=

    *

  • 1.x+=bx=x+b.2.x-=bx=x-b.3.x*=bx=x*b.4.x/=bx=x/b.5.x%=bx=x%b.6.x&=bx=x&b.7.x|=bx=x|b.8.x^=bx=x^b.9.xb.11.x>>>=bx=x>>>b.. Task9

    *

  • () [ ] ++ -- + - ~ !, , , , , * / %, , + -, >> >>> >= <

  • == != , & ^ | && || ? : =op (op )

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *

    *