About 38,900,000 results
Open links in new tab
  1. java - How to get boolean user input using scanner ... - Stack Overflow

    Feb 6, 2015 · Just off the topic, replace your if(bn == true) with if(bn). What input values have you tried? slight tweak to your program. This works. do { try { System.out.print("Are you above 18?"); Scanner n = new Scanner(System.in); boolean bn = n.nextBoolean(); if (bn == true) { System.out.println("Over 18"); } else if (bn == false) {

  2. Scanner nextBoolean() method in Java with Examples

    Oct 12, 2018 · The nextBoolean () method of java.util.Scanner class scans the next token of the input as a Boolean. If the translation is successful, the scanner advances past the input that matched. Syntax: Parameters: The function does not accepts any parameter. Return Value: This function returns the Boolean scanned from the input.

  3. Java Scanner nextBoolean() Method - W3Schools

    The nextBoolean() method returns the boolean value that the next token represents. A token represents a boolean value if its value matches one of the strings "true" or "false". The match is case-insensitive, which means that values like "True" and …

  4. java - Read in input text Yes/No Boolean from user to proceed …

    Feb 15, 2022 · Use Scanner and get next line, then check if that line is yes or no then handle respectively. In the example below, I used a while loop to keep asking them to input yes or no in case they enter something different like "maybe". For example: // Use this to check if it is yes or no. if(line.equalsIgnoreCase("yes")){ // Process yes. break;

  5. java - How can get boolean user Input - Stack Overflow

    Aug 26, 2017 · When I input in the program like this: boolean a = (true & false) & true; It's worked. But when I input from the keyboard by using Scanner: Scanner sc = new Scanner(System.in); boolean b...

  6. Java User Input (Scanner class) - W3Schools

    Java User Input. The Scanner class is used to get user input, and it is found in the java.util package. To use the Scanner class, create an object of the class and use any of the available methods found in the Scanner class documentation. In our example, we will use the nextLine() method, which is used to read Strings:

  7. Java Scanner (With Examples) - Programiz

    Scanner input = new Scanner(System.in); System.out.print("Enter your name: "); // takes input from the keyboard . String name = input.nextLine(); // prints the name . System.out.println("My name is " + name); // closes the scanner . input.close(); Output. In …

  8. Java User Input – Scanner Class - GeeksforGeeks

    Apr 22, 2025 · The most common way to take user input in Java is using the Scanner class. It is a part of java.util package. The scanner class can handle input from different places, like as we are typing at the console, reading from a file, or working with data streams. This class was introduced in Java 5. Before

  9. Java Scanner nextBoolean() method example - Java Tutorial HQ

    This java tutorial shows how to use the nextBoolean method of Scanner class of java.util package. This method returns boolean data type which corresponds to the interpreted boolean value of the scanner input. This method simply returns the next token of the input boolean value.

  10. How To Take Input In Java | Scanner Class & More (+Examples) …

    Let’s break down the steps to take user input in Java programming language using this class. Import the Class: Begin by importing java.util.Scanner to gain access to the Scanner class. Create a Scanner Object: Instantiate a Scanner object by wrapping System.in the standard input stream.

Refresh