An If Else statement follows the following structure If


Download 13.72 Kb.
Sana04.05.2020
Hajmi13.72 Kb.
#103169
Bog'liq
Conditional statements


An If...Else statement follows the following structure

If (condition_to_test) {

//result if condition is true

}

Else {



//result if condition is false

}

The program below tests whether a user visiting a site has attained the minimum age required which is 18 years of age, thus this becomes the (condition_to_test). If the test returns a true value then the user is allowed to proceed to the website, otherwise, access is denied.



public class IfElseExample {

    public static void main (String[] args) {

        int user=17;

        if (user<=18) {

            System.out.println("User cannot proceed to view the website");

        } 

else {

            System.out.println("User is allowed to visit website");



        }

    }


}
Download 13.72 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling