diff --git a/src/java/lesson1/classwork/Conditions.java b/src/java/lesson1/classwork/Conditions.java new file mode 100644 index 0000000..ba9ea43 --- /dev/null +++ b/src/java/lesson1/classwork/Conditions.java @@ -0,0 +1,38 @@ +package lesson1.classwork; + +import java.util.Scanner; + +public class Conditions { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); +// System.out.println("Введите а"); +// int a = in.nextInt(); +// System.out.println("Введите b"); +// int b = in.nextInt(); +// System.out.println("Большее из двух: "); +// if (a > b) { +// System.out.println("a"); +// } else { +// System.out.println("b"); +// } + // 1 2 3 4 + //.....0.....7.....12........ + int x = in.nextInt(); + if (x < 0) { + System.out.println("1"); + } else if (x < 7) { + System.out.println("2"); + } else if (x < 12) { + System.out.println("3"); + } else { + System.out.println("4"); + } + +// if (x < 0) {} +// if (x >= 0 && x < 7){} +// if (x >= 7 && x < 12){} +// if (x >= 12){} + boolean condition1 = x > 7, condition2 = x < 12; + //>, <, >=, <=, ==, != + } +} diff --git a/src/java/lesson1/classwork/Functions.java b/src/java/lesson1/classwork/Functions.java new file mode 100644 index 0000000..da71477 --- /dev/null +++ b/src/java/lesson1/classwork/Functions.java @@ -0,0 +1,20 @@ +package lesson1.classwork; + +public class Functions { + + static int funcName(int a, int b) { + return a + b; + } + + static int foo(long a) { + return (int)a; + } + + static void print(int a) { + System.out.println(a); + } + + public static void main(String[] args) { + print(12); + } +} diff --git a/src/java/lesson1/classwork/Main.java b/src/java/lesson1/classwork/Main.java new file mode 100644 index 0000000..60b74b7 --- /dev/null +++ b/src/java/lesson1/classwork/Main.java @@ -0,0 +1,31 @@ +package lesson1.classwork; + +import java.math.BigInteger; + +public class Main { + public static void main(String[] args) { + //примитивные типы данных + //integers + byte b = -128; //1b = 8bit (2 ** 8 = 256) + //[-128; 128) -128 ... - 1 0 1 2 3 ... 127 + short sh = 32736; // 2b = 16 bit + // [-2 ** 15; 2 ** 15) + int i = 2_000_000_000; // 4b = 32 bit + long l = 1_000_000_000_000_000_000L; // 8b = 64 bit + System.out.println(l); + // 10 ** 18 + //BigInteger bi = new BigInteger("0"); + //floating point + final int a = 12; + float f = 121212.6565656f; // 4 b + double d = 121212.6565656; // 8 b + char c = 's';// ' " \ + System.out.println((char)(c + 1)); + boolean bool = c < 'S' + 33; + //boolean b1; + System.out.println(bool); + String str = "+79112756975"; + System.out.println(str.matches("\\+7[0-9]{10}")); + } + +} diff --git a/src/java/lesson1/classwork/Mat.java b/src/java/lesson1/classwork/Mat.java new file mode 100644 index 0000000..f5b6b47 --- /dev/null +++ b/src/java/lesson1/classwork/Mat.java @@ -0,0 +1,24 @@ +package lesson1.classwork; + +public class Mat { + public static void main(String[] args) { + int x = 5, y = 3; + float xf = 5, yf = 3; + System.out.println(x / y); + System.out.printf("%.16f\n", xf / yf); + // + - * / (% - остаток) >> << + //++ -- += /= *= %= + //System.out.println(++x); + System.out.println(x); + x = x++ + ++x; //5 = 5(6) + 7 = 12 + System.out.println(x); + x -= 5; x += 2; x *= 2; x /= 3; + x = x % 4; + System.out.println(x); + x = 12; + System.out.println(Integer.toBinaryString(x)); + x <<= 3; // x = x << k <=> x = x * (2 ** k) + System.out.println(x); + System.out.println(Integer.toBinaryString(x)); + } +}