About 7,110 results
Open links in new tab
  1. java - Yes/No with boolean or if/else? - Stack Overflow

    Apr 10, 2013 · String answer = in.nextLine() Boolean yn = (answer.equalsIgnoreCase("Y") ? true : false); Or, you can use a shorter form: Boolean yn = (answer.equalsIgnoreCase("Y")); If you meant something else please post a clarification.

  2. Java Booleans - W3Schools

    For this, Java has a boolean data type, which can store true or false values. A boolean type is declared with the boolean keyword and can only take the values true or false: However, it is more common to return boolean values from boolean expressions, for conditional testing (see below). A Boolean expression returns a boolean value: true or false.

  3. What is the correct way to declare a boolean variable in Java?

    Aug 1, 2016 · First of all, you should use none of them. You are using wrapper type, which should rarely be used in case you have a primitive type. So, you should use boolean rather. Further, we initialize the boolean variable to false to hold an initial default value which is false.

  4. boolean Keyword in Java: Usage & Examples - DataCamp

    The boolean keyword in Java is a primitive data type that can hold only two possible values: true or false. It is used to represent simple flags that track true/false conditions, and it is the basis for all conditional operations in Java.

  5. java for complete beginners - boolean values - Home and Learn

    Boolean Data Values in Java. A Boolean value is one with two choices: true or false, yes or no, 1 or 0. In Java, there is a variable type for Boolean values: boolean user = true; So instead of typing int or double or string, you just type boolean (with a lower case "b").

  6. Java BooleanWhat Is A Boolean In Java (With Examples)

    Apr 1, 2025 · Learn what is a Boolean in Java, how to declare & return a Java Boolean, and what are boolean operators along with practical code examples: In this tutorial, we are going to explore boolean in Java which is a primitive data type.

  7. if statement - if (boolean condition) in Java - Stack Overflow

    Oct 4, 2018 · if(condition){ // Executes when condition evaluates to true. } else{ // Executes when condition evaluates to false. In your case you are directly passing a boolean value so no evaluation is required. Share

  8. The simplest if-statement has two parts – a boolean "test" within parentheses ( ) followed by "body" block of statements within curly braces { }. The test can be any expression that evaluates to a boolean value – true or false – value (boolean expressions are detailed below).

  9. Java Programming/Boolean variables - Wikiversity

    Aug 2, 2020 · Conditional operators operate only on boolean values. Java has three, conditional-and, conditional-or, and conditional-not (there is another kind of and, or and not that will be covered later, thus the distinction). The operator for conditional-and is a pair of adjacent ampersand characters &&.

  10. Master Java Booleans: Guide with Examples and Use Cases

    Dec 19, 2024 · In Java, booleans represent a type of data that can hold one of two possible values: true or false. These values are primarily used for decision-making in conditional statements and logical operations.

Refresh