|
| 1 | +import java.util.Scanner; |
| 2 | + |
| 3 | +class Main { |
| 4 | + public static void main(String[] args) { |
| 5 | + Scanner input = new Scanner(System.in); |
| 6 | + System.out.println("hello"); |
| 7 | + System.out.println("1"); |
| 8 | + // int [-2^31, 2^31) |
| 9 | + // long [-2^63, 2^63) |
| 10 | + // double 64-bit |
| 11 | + // float 32-bit |
| 12 | + // boolean true false |
| 13 | + // String "asdasd 123dasd" |
| 14 | + |
| 15 | + String parsa; |
| 16 | + parsa = " "; |
| 17 | + String parsaa = " "; |
| 18 | + |
| 19 | + parsa = "lala"; |
| 20 | + int r = 2; |
| 21 | + long a = 2; |
| 22 | + double t = 2.0; |
| 23 | + boolean c; |
| 24 | + c = true; |
| 25 | + c = false; |
| 26 | + double da = 0.1; |
| 27 | + double db = 0.2; |
| 28 | + double dsum = da + db; |
| 29 | + System.out.println(dsum); // 0.3? |
| 30 | + |
| 31 | + // + - * / % |
| 32 | + // += -= *= /= %= |
| 33 | + a = a + 1; |
| 34 | + a += 1; |
| 35 | + // 7 % 2 |
| 36 | + // < > <= >= == != |
| 37 | + // 1 == 2 |
| 38 | + // 1 != 2 |
| 39 | + |
| 40 | + // ++ -- |
| 41 | + int aa = 1; |
| 42 | + aa++; |
| 43 | + aa = aa + 1; |
| 44 | + aa += 1; |
| 45 | + aa--; |
| 46 | + aa = aa - 1; |
| 47 | + aa -= 1; |
| 48 | + |
| 49 | + int first = input.nextInt(); |
| 50 | + int second = input.nextInt(); |
| 51 | + int sum = first + second; |
| 52 | + System.out.println(sum); |
| 53 | + int n = input.nextInt(); |
| 54 | + if (n % 3 == 0) { |
| 55 | + System.out.println("salam"); |
| 56 | + } |
| 57 | + else if (n % 3 == 1) { |
| 58 | + System.out.println("hello"); |
| 59 | + } |
| 60 | + else { |
| 61 | + System.out.println("bye"); |
| 62 | + } |
| 63 | + int m = input.nextInt(); |
| 64 | + int sum1 = 0; |
| 65 | + int j = 1; |
| 66 | + while (j <= m) { |
| 67 | + sum1 += j; |
| 68 | + j++; |
| 69 | + } |
| 70 | + System.out.println(sum1); |
| 71 | + |
| 72 | + int k = 1; |
| 73 | + while (k <= n) { |
| 74 | + // code |
| 75 | + k++; |
| 76 | + } |
| 77 | + |
| 78 | + // for (int i = 1; i <= n; i++) { |
| 79 | + // code |
| 80 | + // } |
| 81 | + |
| 82 | + // for (int i = 100; i >= 0; i /= 2) { |
| 83 | + // } |
| 84 | + |
| 85 | + Math.max(2, 3); |
| 86 | + Math.min(2, 3); |
| 87 | + String s = "hello"; |
| 88 | + char ch = 'a'; |
| 89 | + // s.charAt(0) == 'h'; |
| 90 | + s.length(); |
| 91 | + // s.substring(i, j); // [i, j) |
| 92 | + // s.substring(1, 2) == "e"; // wrong, correct form: |
| 93 | + // s.substring(1, 2).equals("e"); |
| 94 | + // s.charAt(1) == 'e'; |
| 95 | + // .equals(); |
| 96 | + String s1 = input.next(); |
| 97 | + String s2 = input.next(); |
| 98 | + // Math.pow(a, b); // a^b |
| 99 | + boolean boo = false; |
| 100 | + // !t |
| 101 | + // if (!s.equals(t)) { // != |
| 102 | + |
| 103 | + // } |
| 104 | + // int a = 1; |
| 105 | + // int b = 2; |
| 106 | + // if (a != b) |
| 107 | + // if (!(a == b)) |
| 108 | + String st = "hello world"; |
| 109 | + if (st.substring(1, 4).equals("ell")) { |
| 110 | + System.out.println("YES"); |
| 111 | + } |
| 112 | + else { |
| 113 | + System.out.println("NO"); |
| 114 | + } |
| 115 | + // Math.sqrt(n); |
| 116 | + |
| 117 | + double rootOfFour = Math.sqrt(4); // 2.0 |
| 118 | + |
| 119 | + // i = 1 ... sqrt(n) |
| 120 | + for (int i = 1; i <= Math.sqrt(n); i++) { |
| 121 | + System.out.println(i); |
| 122 | + } |
| 123 | + // OR |
| 124 | + for (int i = 1; i * i <= n; i++) { |
| 125 | + System.out.println(i); |
| 126 | + } |
| 127 | + // Second approach is better, because it doesn't have imprecision, |
| 128 | + // and it's faster because Math.sqrt is expensive in terms of time. |
| 129 | + for (int i = 1; i <= 10; i++) { |
| 130 | + if (i == 5) { |
| 131 | + continue; |
| 132 | + } |
| 133 | + System.out.println(i); |
| 134 | + } |
| 135 | + |
| 136 | + // || && ! |
| 137 | + // if (1 == 2 || 2 == 2) { |
| 138 | + // condition is true; |
| 139 | + // } |
| 140 | + // if (1 == 2 && 2 == 2) { |
| 141 | + // condition is false; |
| 142 | + // } |
| 143 | + int[] array = new int[5]; |
| 144 | + for (int i = 0; i < 5; i++) { |
| 145 | + array[i] = (i + 1) * (i + 1); |
| 146 | + } |
| 147 | + // OR |
| 148 | + for (int i = 1; i <= 5; i++) { |
| 149 | + array[i - 1] = i * i; |
| 150 | + } |
| 151 | + for (int i = 0; i < 5; i++) { |
| 152 | + System.out.print(array[i] + " "); |
| 153 | + } |
| 154 | + } |
| 155 | +} |
0 commit comments