Skip to content
Advertisement

My current if statement with the logical II OR is having compile error [closed]

I am learning Java and following code is not working, can you please check and see what I did wrong? Thanks.

public class HelloWorld{

    public static void main(String []args){
        /*
         Ticket price: 10 normally

        Discounted price , 5 for:
        - Age 15 and under
        - Over the age 60
        - Students
        */
        int ticketPrice = 10;
        int age = 16;
        boolean isStudent = false;
        
        if( (age =< 15) || (age>60) ){
            ticketPrice = 5;
        }else if (isStudent){
            ticketPrice = 5;
        }
        System.out.println("The price is: "+ ticketPrice);
     }
}

Advertisement

Answer

It’s <= (Less than or Equal to), not =<.

public class HelloWorld
{
    public static void main(String []args)
    {
        /*
        Ticket price: 10 normally

        Discounted price , 5 for:
        - Age 15 and under
        - Over the age 60
        - Students          */
    
        int ticketPrice = 10;
        int age = 16;
        boolean isStudent = false;

        if ( (age <= 15) || (age>60) || (isStudent) )
            ticketPrice = 5;
        System.out.println("The price is: "+ ticketPrice);
    }
}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement