середа, 22 листопада 2017 р.

Оголошення змінних. Ідентифікатори. Ключові слова. Типи даних String, int. Oператор System.out.print(). Конкатенація

Програми:

public class NameOutput_2 {
            public static void main(String args[]) {
                        //System.out.println("Serg");
//заміна літерального імені змінною
                        String name = "Serg";
System.out.println(name);
            }
}
*******************************************************************
public class Variables_1 {
            public static void main(String args[]) {
//оголошення та виведення змінної типу int
int x = 10;
System.out.println(x);
            }
}
*******************************************************************
public class Variables_2 {
            public static void main(String args[]) {
//приклади неправильних або некоректних ідентифікаторів
int dog Price = 100; // неправильно – ідентифікатор містить пробіл
int dog-Price = 100; // неправильно – ідентифікатор містить тире
int DogPrice = 100; // правильно, проте некоректно: порушено Code
                                   //Convention – ідентифікатор починається з            
                                   //прописної букви
            }
}
*******************************************************************
public class Variables_3 {
            public static void main(String args[]) {
//приклади неправильних ідентифікаторів, що використовують ключові слова
int assert = 100; // неправильно – ідентифікатор є ключовим словом
            }
}
*******************************************************************
public class Variables_4 {
            public static void main(String args[]) {
//приклади арифметичних операцій
int x = 100,
int y = 8;
int z = x+y;
System.out.println(z);
System.out.println(x-y);
System.out.println(x*y);
            }
}

*******************************************************************
public class Variables_5 {
            public static void main(String args[]) {
//виведення декількох змінних в одному рядку оператором System.out.print();
int x = 100;
int y = 8;
System.out.print(“x + y = ”);
System.out.print(x+y);
            }
}
*******************************************************************
public class Variables_6 {
            public static void main(String args[]) {
//особливості конкатенації;
int x = 100;
int y = 8;
// System.out.println(x + y = ”, x+y);   //не компілюється
// System.out.println(“x + y = ”+x+y);   //компілюється, але вивід
                                                                          //невірний:  x + y = 1008
// System.out.println(“x + y = ”+(x+y)); //компілюється, вивід вірний
            }
}

Література для класної роботи:

Тести для класної роботи
[task-mughal] – №2.3 (п.4):

Is this a complete and legal comment? Select the one correct answer.
 
/* // */
a.    No, the block comment (/* ... */) is not ended since the single-line comment (// ...) comments out the closing part.
b.    It is a completely valid comment. The // part is ignored by the compiler.
c.    This combination of comments is illegal and the compiler will reject it.




Література для домашньої роботи:

Тести для домашньої роботи
[task-mughal] – №2.1, 2.2:

Which of the following is not a legal identifier?  Select the one correct answer.
a.    a2z
b.    52pickup
c.    _class
d.    ca$h
e.    total#
Which statement is true?  Select the one correct answer.
a.    new and delete are keywords in the Java language.
b.    trycatch, and thrown are keywords in the Java language.
c.    staticunsigned, and long are keywords in the Java language.
d.    exitclass, and while are keywords in the Java language.
e.    returngoto, and default are keywords in the Java language.
f.     forwhile, and next are keywords in the Java language.

Немає коментарів:

Дописати коментар

Архів блогу