import java.util.Scanner; public class BooleanInput { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a boolean value: "); boolean boolValue = input.nextBoolean(); System.out.println("The value you entered is: " + boolValue); } }
import java.util.Scanner; public class AgeCheck { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter your age: "); int age = input.nextInt(); System.out.println("Are you above 18 years of age? (true/false): "); boolean isAdult = input.nextBoolean(); if((age < 18) && isAdult) { System.out.println("You cannot be an adult below 18"); } else if((age >= 18) && !isAdult) { System.out.println("You cannot be below 18 years of age"); } else { System.out.println("Your age and adult status match"); } } }In the above example, we have used `nextBoolean` to check if the user is above 18 years of age or not. Depending on the user input, we are displaying different outputs.