|
| 1 | +public class B3nkos { |
| 2 | + public static void main(String[] args) { |
| 3 | + // assignment operators |
| 4 | + int numberOne = 2; |
| 5 | + int numberTwo = 6; |
| 6 | + int numberThree = 9; |
| 7 | + |
| 8 | + System.out.printf("numberOne = %d\n", numberOne); |
| 9 | + System.out.printf("numberTwo = %d\n", numberTwo); |
| 10 | + System.out.printf("numberThree = %d\n", numberThree); |
| 11 | + |
| 12 | + System.out.println(); |
| 13 | + |
| 14 | + // arithmetic operator |
| 15 | + System.out.printf("numberOne + numberTwo = %d\n", numberOne + numberTwo); |
| 16 | + System.out.printf("numberThree - numberOne = %d\n", numberThree - numberOne); |
| 17 | + System.out.printf("numberOne * numberThree = %d\n", numberOne * numberThree); |
| 18 | + System.out.printf("numberThree / numberOne = %d\n", numberThree / numberOne); |
| 19 | + System.out.printf("numberThree %% numberOne = %d\n", numberThree % numberOne); |
| 20 | + numberOne++; |
| 21 | + numberThree--; |
| 22 | + System.out.printf("numberOne++ = %d\n", numberOne); |
| 23 | + System.out.printf("numberThree-- = %d\n", numberThree); |
| 24 | + System.out.printf("numberThree+=3 = %d\n", numberThree+=3); |
| 25 | + |
| 26 | + System.out.println(); |
| 27 | + |
| 28 | + // comparison operators |
| 29 | + System.out.printf("numberThree > numberOne = %b\n", numberThree > numberOne); |
| 30 | + System.out.printf("numberThree <= numberOne = %b\n", numberThree <= numberOne); |
| 31 | + System.out.printf("numberThree >= numberOne = %b\n", numberThree >= numberOne); |
| 32 | + |
| 33 | + System.out.println(); |
| 34 | + |
| 35 | + // logic operators |
| 36 | + System.out.printf("true and false = %b\n", true && false); |
| 37 | + System.out.printf("true and true = %b\n", true && true); |
| 38 | + System.out.printf("true or false = %b\n", true || false); |
| 39 | + System.out.printf("false or true = %b\n", false || true); |
| 40 | + System.out.printf("!true = %b\n", !true); |
| 41 | + System.out.printf("!false = %b\n", !false); |
| 42 | + System.out.printf("true is equals to true = %b\n", true == true); |
| 43 | + |
| 44 | + System.out.println(); |
| 45 | + |
| 46 | + // bits operators |
| 47 | + System.out.printf("numberThree >> 2 = %d\n", numberThree >> 2); |
| 48 | + System.out.printf("numberOne << 1 = %d\n", numberOne << 1); |
| 49 | + |
| 50 | + System.out.println(); |
| 51 | + |
| 52 | + // if control structure |
| 53 | + |
| 54 | + if (numberThree > numberOne) { |
| 55 | + System.out.printf("%d is greater than %d\n", numberThree, numberOne); |
| 56 | + } |
| 57 | + |
| 58 | + // switch control structure |
| 59 | + String animal = "Lion"; |
| 60 | + switch (animal) { |
| 61 | + case "Dog" -> System.out.println("The animal is a Dog"); |
| 62 | + case "Lion" -> System.out.println("The animal is a Lion"); |
| 63 | + case "Cat" -> System.out.println("The animal is a Cat"); |
| 64 | + default -> System.out.println("Number not found"); |
| 65 | + } |
| 66 | + |
| 67 | + // while loop |
| 68 | + int c = 1; |
| 69 | + while (c <= 5) { |
| 70 | + System.out.printf("While Loop iteration number #%d\n", c); |
| 71 | + c++; |
| 72 | + } |
| 73 | + |
| 74 | + System.out.println(); |
| 75 | + |
| 76 | + int k = 0; |
| 77 | + do { |
| 78 | + k++; |
| 79 | + System.out.printf("Do-While loop iteration #%d\n", k); |
| 80 | + } while (k < 5); |
| 81 | + |
| 82 | + System.out.println(); |
| 83 | + |
| 84 | + // for loop |
| 85 | + for (int i = 1; i <= 5; i++) { |
| 86 | + System.out.printf("For Loop iteration number #%d\n", i); |
| 87 | + } |
| 88 | + |
| 89 | + System.out.println(); |
| 90 | + |
| 91 | + // EXTRA |
| 92 | + for (int i = 10; i <= 55; i++) { |
| 93 | + if (i == 16 || i % 3 == 0 || i % 2 != 0) { |
| 94 | + continue; |
| 95 | + } |
| 96 | + |
| 97 | + System.out.println(i); |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments