//Sample_21_16.java import java.io.Console; public class Sample_21_16 { private static Console cons = System.console(); public static Boolean getBoolean(String msg){ Boolean yes = null; char ch = ' '; String str = cons.readLine(msg); if(str.length() != 0){ ch = str.charAt(0); } if(ch=='y' || ch=='Y' || ch=='n' || ch=='N'){ yes = ch!='n' && ch!='N'; } return yes; } public static void main(String[] args) { int floor = 1; boolean bool = getBoolean("Do you go up the stairs? (y/n): "); System.out.println("echo : " + bool); if(bool){ floor++; System.out.println("Went up to the " + floor + " floor"); }else{ System.out.println("On the " + floor + " floor"); } } }