This project simulates tracking a character's health in a game environment. It demonstrates the practical use of unary operators: increment (++) and decrement (--).
- Declare an
intvariableheroHealthand set it to 10. - Increase health by 1 using the increment operator and display the result.
- Decrease health by 1 using the decrement operator.
- Print the final value of
heroHealthagain. Include descriptions of game moments in the console output.
After running the program, the console should display:
Health after bonus: 11, because the hero found the cure.
Health after damage: 10, because a brick fell on the hero.
- Language: Java 23
- IDE: IntelliJ IDEA
- Concepts: Increment/Decrement operators, Variable state management.
The code follows Java naming conventions and clean code principles. Each state change is followed by an informative console message.
The code demonstrates how the state of a single variable changes after applying unary operators:
package com.yurii.pavlenko;
public class Task_11_App {
public static void main(String[] args) {
// Initial health level
int heroHealth = 10;
// Increase health by 1 using increment operator
heroHealth++;
System.out.println("Health after bonus: " + heroHealth + ", because the hero found the cure.");
// Decrease health by 1 using decrement operator
heroHealth--;
System.out.println("Health after damage: " + heroHealth + ", because a brick fell on the hero.");
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT