Presentation is loading. Please wait.

Presentation is loading. Please wait.

Основы языка. 1.Переменные 2.Операторы 3.Примитивные типы 4.Массивы 5.Выражения 6.Блоки 7.Управление циклами.

Similar presentations


Presentation on theme: "Основы языка. 1.Переменные 2.Операторы 3.Примитивные типы 4.Массивы 5.Выражения 6.Блоки 7.Управление циклами."— Presentation transcript:

1 Основы языка

2 1.Переменные 2.Операторы 3.Примитивные типы 4.Массивы 5.Выражения 6.Блоки 7.Управление циклами

3 Переменные Переменные объекта Переменные класса Локальные переменные Параметры Именование – $gear1, _gear, gear, gearRatio и NUM_GEARS – 1$gear, 1_gear, 1gear, int…

4 Примитивные типы НазваниеМинимальное значениеМаксимальное значение byte-128127 short-32,76832,767 int-2,147,483,6482,147,483,647 long-9,223,372,036,854,775,8089,223,372,036,854,775,807 float32-bit double64-bit booleantrueFlase char\u0000 (0)\uffff (65,535 )

5 Default Values Data TypeDefault Value (for fields) byte0 short0 int0 long0L float0.0f double0.0d char'\u0000' String (or any object) null booleanfalse

6 Литералы boolean result = true; char capitalC = 'C'; byte b = 100; short s = 10000; int i = 100000; // The number 26, in decimal int decVal = 26; // The number 26, in hexadecimal int hexVal = 0x1a; // The number 26, in binary int binVal = 0b11010;

7 double d1 = 123.4; // same value as d1, but in scientific //notation double d2 = 1.234e2; float f1 = 123.4f;

8 Array // declares an array of integers int[] anArray; // allocates memory for 10 integers anArray = new int[10]; // initialize first element anArray[0] = 100; // initialize second element anArray[1] = 200;

9 Операторы OperatorsPrecedence postfixexpr++ expr-- unary++expr --expr +expr -expr ~ ! multiplicative* / % additive+ - shift > >>> relational = instanceof equality== != bitwise AND& bitwise exclusive OR^ bitwise inclusive OR| logical AND&& logical OR|| ternary? : assignment= += -= *= /= %= &= ^= |= >= >>>=

10 Выражения и блоки Выражение if (value1 == value2) System.out.println("value1 == value2"); Statements // assignment statement float aValue = 8933.234f; Блоки if (condition) { // begin block 1 int q = 0; System.out.println("Condition is true."); } // end block one

11 Блоки if-then if (isMoving){ // the "then" clause: decrease // current speed currentSpeed--; } if-then-else if (isMoving) { currentSpeed--; } else { System.err.println("The bicycle has already stopped!"); } switch int month = 8; String monthString; switch (month) { case 1: monthString = "January"; break; case 2: monthString = "February"; break; default: monthString = "Invalid month"; break; } System.out.println(monthString);

12 while and do-while while (expression) { statement(s) } do { statement(s) } while (expression); for for (initialization; termination; increment) { statement(s) } int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for (int item : numbers) { System.out.println("Count is: " + item); }

13 break for (i = 0; i < arrayOfInts.length; i++) { if (arrayOfInts[i] == searchfor) { foundIt = true; break; } Continue for (int i = 0; i < max; i++) { // interested only in p's if (searchMe.charAt(i) != 'p') continue; // process p's numPs++; } return

14 Q&A


Download ppt "Основы языка. 1.Переменные 2.Операторы 3.Примитивные типы 4.Массивы 5.Выражения 6.Блоки 7.Управление циклами."

Similar presentations


Ads by Google