- In Java programming, the term "flag" typically refers to a variable used as a signal or indicator within a program's flow. It's a common programming concept, not specific to Java, but widely applied in various contexts within Java development. Boolean Flags:
- The most common type of flag is a boolean variable. It holds a true or false value, indicating whether a specific condition has been met or a particular state exists. Sample program :
boolean foundEven = false;
for (int num : numbers) {
if (num % 2 == 0) {
foundEven = true; // Set the flag
break;
}
}
if (foundEven) {
System.out.println("An even number was found.");
}
REFFERED LINKS:
Top comments (0)