Last active
October 29, 2015 15:44
-
-
Save FreeFly19/15359b67fb39f2201615 to your computer and use it in GitHub Desktop.
Sekta Java Class Work 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Це багатостроковий коментар, який ніяк не впливає на виконання програми | |
Тут можна написати хто створив це файл, або інші відомості, які мають значення | |
для читача коду, але не мають значення для компілятора(хто не знає що це таке, прочитайте) | |
Приміть до уваги, ім'я файлу та ім'я класу, який описаний нижче повинні співпадати | |
*/ | |
class ClassTask1{ | |
public static void main(String[] args){ | |
// Це одностроковий коментар | |
// System.out.println - це функція, яка виклакається для виводу тексту або значення якоїсь змінної в консоль | |
// А також потім робить перенос строки | |
System.out.println("Hello, world!!!"); | |
// Можете написати sout і нажати клавішу Tab, тоді воно автоматично напише "System.out.println()" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassTask2{ | |
public static void main(String[] args){ | |
// Функція System.out.print аналогічна до System.out.println, але вона не робить перенос строки після тексту який виводить | |
System.out.print("Hello, "); | |
System.out.println("world!!!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassTask3{ | |
public static void main(String[] args){ | |
// = - цей знак називається "знаком присвоєння" | |
int a; // Створення зміної "а", яка буде містити в собі цілі числа(int - integer) | |
a = 5; // Присвоєння змінній "а" значення "5" | |
a = 10; // тепер в змінній "а" лежить 10 | |
a = a + 5// це означає a = старе значення а + 5 | |
// тобто a = 10 + 5 | |
System.out.println(a); // Вивід в консоль значення змінної "а" | |
String s = "Line of text"; // Створення змінної "s", та задання значення - цей процес називається ініціалізація змінної | |
System.out.println(s); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassTask4{ | |
public static void main(String[] args){ | |
int a = 8; | |
int b = 9, c; // Зміні можна створювати через кому | |
c = a + b; // Над цілочисельними зміними можна виконувати математичні дії | |
// + додавання | |
// - віднімання | |
// * множення | |
// % остаток від ділення 17%3 == 2 | |
// / цілочисельне ділення 17/3 == 5 | |
System.out.println(c); | |
System.out.println(c%3);// Ці дії можна використовувати навіть при виводі | |
// також тут працюють дужки як в математиці для вказання пріоритету | |
c = a * (b + 3); | |
System.out.println(c); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassTask5{ | |
public static void main(String[] args){ | |
// Умовний оператор(оператор гілкування, на рос. "ветвления") | |
// Може виконувати одну із двох дій в залежності від виконання або не виконання певної умови | |
if(true){// true - спеціальне зарезервоване слово, означає виконання певної умови, протележне слово false | |
System.out.println("This is true"); | |
} else { | |
System.out.println("This is false"); | |
} | |
// Вище наведена повна форма оператора if(з else) | |
// Він має ще не повну форму, без оператора else | |
// його застосовують коли є певна умова та дія, яка повина виконатись при виконанні умови | |
// Але у випадку невиконання умови нічого відбуватись не повинно, наприклад: | |
// 1 не дорівнює 3, тому нічого не відбудеться | |
// == - це знак перевірки на рівність, змінні можуть дорівнювати одна іншій, або ні | |
// результатом цієї дії, буде true або false. | |
if(1 == 3){ | |
System.out.println("You will be not see this text."); | |
} | |
int a = 5, b = 10; | |
// > - це знак "меньше" | |
// результатом цієї дії, буде true або false. | |
if(a > b){ // результатом цієї дії буде false | |
System.out.println("5 more that 10");// це невірно | |
} else { | |
System.out.println("5 less that 10"); | |
} | |
// є наступні оператори для порівнання чисел | |
// == перевірка на рівність | |
// != перевірка на нерівність | |
// < меньше | |
// > більше | |
// <= меньше або рівне | |
// >= більше або рівне | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassTask6{ | |
public static void main(String[] args){ | |
// Циклічний оператор for | |
// Даю лише приклади, про нього почитаєте в інтеренеті самі | |
// зверніть увагу, цей оператор є в багатьох мовах програмування, шукайте саме Java | |
for(int i = 0; i < 5; i++){ | |
System.out.print(i); | |
System.out.print(" "); | |
} | |
System.out.println(); | |
System.out.println(); | |
for(int i = 0; i <= 9; i = i + 3){ | |
System.out.print(i); | |
System.out.print(" "); | |
} | |
System.out.println(); | |
System.out.println(); | |
for(int i = 9; i != 5; i = i - 1){ | |
System.out.print(i); | |
System.out.print(" "); | |
} | |
System.out.println(); | |
System.out.println(); | |
for(int a = 0; a < 10; a++){ | |
if(a % 3 == 0){//Якщо а кратне трьом | |
System.out.print(a); | |
System.out.print(" "); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassTask7{ | |
public static void main(String[] args){ | |
//Приклад вложених циклів для тих хто вижив після того всього, що там написюкано | |
for (int i = 1; i <= 9; i++) { | |
for (int j = 1; j < 10 ; j++) { | |
System.out.print(i*j); | |
System.out.print("\t");// \t - спеціальний знак табуляції, по суті пробіл автоматичної довжини | |
} | |
System.out.println(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassTask8{ | |
public static void main(String[] args){ | |
// Якась фігнюшка красива на останок :) | |
// Якщо зовсім скучно можете подивитись | |
for (int i = 1; i <= 9; i++) { | |
for (int j = 1; j < 10 ; j++) { | |
if (i == 5 || j == 5) { | |
System.out.print(" * "); | |
} else { | |
System.out.print(" "); | |
} | |
} | |
System.out.println(); | |
} | |
for (int i = 1; i <= 9; i++) { | |
for (int j = 1; j < 10 ; j++) { | |
if (i==j) { | |
System.out.print(" * "); | |
} else { | |
System.out.print(" "); | |
} | |
} | |
System.out.println(); | |
} | |
for (int i = 1; i <= 9; i++) { | |
for (int j = 1; j < 10 ; j++) { | |
if (10-i==j) { | |
System.out.print(" * "); | |
} else { | |
System.out.print(" "); | |
} | |
} | |
System.out.println(); | |
} | |
for (int i = 1; i <= 9; i++) { | |
for (int j = 1; j < 10 ; j++) { | |
if (i==j || i==5 || j==5 || 10-i == j) { | |
System.out.print(" * "); | |
} else { | |
System.out.print(" "); | |
} | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment