Friday, April 8, 2011

Learning Java 06 - Condition "if-then-else"

Here's a simple program about condition using "if" then followed by "else".

import java.util.*;
public class condition1{
    public static void main(String[]args){
   
    Scanner genioler = new Scanner(System.in);
   
    System.out.print("Enter your age: ");
    int age = genioler.nextInt();
   
    if (age <= 17){
        System.out.println("You are not allow to enter");
    }
    else {
        System.out.println("You are allow to enter");
    }
       
}
}

Note:
( == ) - equal
( > ) - greater than
( < ) - less than
( >= ) - greater than or equal
( <= ) - less than or equal
( != or <>) - not equal
( && ) - and
( || ) - or

No comments:

Post a Comment