Online Java Compiler By
JavaTpoint.com
public class BooleanToStringExample3 { static Boolean b1 = true; int age; static void getAge(int age){ // calling static toString Method() while (Boolean.toString(b1)=="true"){ System.out.println("Your age is "+age +" years."); b1 = true; String str = Boolean.toString(b1); if(age>17){ System.out.println("You eligible to enter the club."); } else{ int val = 18-age; System.out.println("Sorry! You are not an adult.\nYou will be eligible after"+val+"year."); } b1 =false; } } public static void main(String[] args) { getAge(9); } }
Output