|
| 1 | +public class operators { |
| 2 | + public static void main(String[] args) { |
| 3 | + // TODO: increment and decrement examples |
| 4 | + // example_1 |
| 5 | + int count = 5; |
| 6 | + System.out.println("Initial count: " + count); |
| 7 | + count++; |
| 8 | + System.out.println("After increment: " + count); |
| 9 | + // example_2 |
| 10 | + int value = 20; |
| 11 | + int result = value--; |
| 12 | + System.out.println("Value after decrement: " + value); |
| 13 | + System.out.println("Result: " + result); |
| 14 | + // TODO: assignment operator examples |
| 15 | + int a = 10; |
| 16 | + int b = a; |
| 17 | + System.out.println("a = " + a + ", b = " + b); |
| 18 | + b += a; |
| 19 | + System.out.println("a = " + a + ", b = " + b); |
| 20 | + b -= a; |
| 21 | + System.out.println("a = " + a + ", b = " + b); |
| 22 | + b *= a; |
| 23 | + System.out.println("a = " + a + ", b = " + b); |
| 24 | + b /= a; |
| 25 | + System.out.println("a = " + a + ", b = " + b); |
| 26 | + b %= a; |
| 27 | + System.out.println("a = " + a + ", b = " + b); |
| 28 | + // TODO: comparison examples |
| 29 | + // example_1 |
| 30 | + int ageJohn = 25; |
| 31 | + int ageAnna = 30; |
| 32 | + System.out.println("ageJohn == ageAnna: " + (ageJohn == ageAnna)); |
| 33 | + // example_2 |
| 34 | + int scorePlayer1 = 50; |
| 35 | + int scorePlayer2 = 45; |
| 36 | + System.out.println("scorePlayer1 != scorePlayer2: " + (scorePlayer1 != scorePlayer2)); |
| 37 | + // example_3 |
| 38 | + double heightBuilding1 = 150.5; |
| 39 | + double heightBuilding2 = 120.3; |
| 40 | + System.out.println("heightBuilding1 > heightBuilding2: " + (heightBuilding1 > heightBuilding2)); |
| 41 | + // example_4 |
| 42 | + int speedCar = 120; |
| 43 | + int speedLimit = 100; |
| 44 | + System.out.println("speedCar < speedLimit: " + (speedCar < speedLimit)); |
| 45 | + // example_5 |
| 46 | + int pointsPlayer = 90; |
| 47 | + int pointsRequired = 90; |
| 48 | + System.out.println("pointsPlayer >= pointsRequired: " + (pointsPlayer >= pointsRequired)); |
| 49 | + // example_6 |
| 50 | + int temperatureToday = 25; |
| 51 | + int temperatureYesterday = 30; |
| 52 | + System.out.println("temperatureToday <= temperatureYesterday: " + (temperatureToday <= temperatureYesterday)); |
| 53 | + // TODO: logical examples |
| 54 | + // example_1 |
| 55 | + boolean isAccountActive = true; |
| 56 | + boolean hasSufficientBalance = true; |
| 57 | + System.out.println("Can make a purchase: " + (isAccountActive && hasSufficientBalance)); |
| 58 | + // example_2 |
| 59 | + boolean hasMembershipCard = false; |
| 60 | + boolean hasDiscountCoupon = true; |
| 61 | + System.out.println("Eligible for discount: " + (hasMembershipCard || hasDiscountCoupon)); |
| 62 | + // example_3 |
| 63 | + boolean isServerDown = false; |
| 64 | + System.out.println("Can access website: " + !isServerDown); |
| 65 | + // example_4 |
| 66 | + boolean isSunny = false; |
| 67 | + boolean hasUmbrella = true; |
| 68 | + boolean wantsToGoOutside = true; |
| 69 | + System.out.println("Can go outside: " + ((isSunny || hasUmbrella) && wantsToGoOutside)); |
| 70 | + // example_5 |
| 71 | + boolean hasJobOffer = true; |
| 72 | + boolean isQualified = false; |
| 73 | + boolean isWillingToLearn = true; |
| 74 | + System.out.println("Can get the job: " + (hasJobOffer && (isQualified || isWillingToLearn))); |
| 75 | + } |
| 76 | +} |
0 commit comments