Assignment Statements Give a value to the declared variable //Assign 1 to x: radius=1.0; //Assign 1.0 to radius; a=A ∥ ssign'A'toa; Liang, Introduction to Java Programming, revised by dai-kaiyt
Liang, Introduction to Java Programming,revised by Dai-kaiyu 16 Assignment Statements ➢Give a value to the declared variable x = 1; // Assign 1 to x; radius = 1.0; // Assign 1.0 to radius; a = 'A'; // Assign 'A' to a;
Assignment Expressions Expression: a computation involving values, glue. variables, and operators that evaluates to a v X=5*(3/2)+3*2; Assignment expressions i=j=k=1; Liang, Introduction to Java Programming, revised by dai-kaiyt
Liang, Introduction to Java Programming,revised by Dai-kaiyu 17 Assignment Expressions Expression: a computation involving values, variables, and operators that evaluates to a value. X = 5 * ( 3 / 2 ) + 3 * 2; Assignment expressions: i = j = k = 1;
Declaring and Initializing in One step o intx=1 ● double c=1.4: ●n0tf=.4; Is this statement correct? A variable in method must be assigned a value before it can be used Liang, Introduction to Java Programming, revised by dai-kaiyt
Liang, Introduction to Java Programming,revised by Dai-kaiyu 18 Declaring and Initializing in One Step ⚫ int x = 1; ⚫ double d = 1.4; ⚫ float f = 1.4; Is this statement correct? A variable in method must be assigned a value before it can be used
Constants final datatype CONSTANTNAME VALUE i final double pi =3. 14159 final int size=3 Liang, Introduction to Java Programming, revised by dai-kaiyt
Liang, Introduction to Java Programming,revised by Dai-kaiyu 19 Constants final double PI = 3.14159; final int SIZE = 3; final datatype CONSTANTNAME = VALUE;
Numerical Data Types byte 8 bits type se range short 16 bits Byte 128~127 Int 32 bits short 2byte-215~215-1 ong 64 bits float 32 bits In bytes|-231~231-1 d ouble 64 bits long bytes 263~263-1 Liang, Introduction to Java Programming, revised by dai-kaiyt
Liang, Introduction to Java Programming,revised by Dai-kaiyu 20 Numerical Data Types byte 8 bits short 16 bits int 32 bits long 64 bits float 32 bits double 64 bits type size range byte 1byte -128 ~ 127 short 2bytes -215 ~ 215-1 int 4bytes -231 ~ 231-1 long 8bytes -263 ~ 263-1