In: Computer Science
A museum's fee policy is that anyone who is either 12 and under or 65 and older receives free admission. Declare a boolean variable named freeAdmissionand set it based on the value in an integer variable age. To receive full credit you should only use one statement. Hint use boolean operators. in Java-Eclipes
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
boolean freeAdmissionand=false; //initialise the
boolean variable , which is false by default
System.out.println("input your age is");
int n=sc.nextInt(); //take the age of the user
here
if(n<=12 || n>=65 ) //checking the condition for
getting the true result
{
freeAdmissionand=true; //true as per the
condition
}
else
{
freeAdmissionand=false; //false as per the
condition
}
System.out.println(freeAdmissionand); //final result
}
}
output here :
feel free to ask anthing & (welcome for any modification in the code)