The if statement is Java's conditional branch statement. It can be used to route program execution through two different paths. The if statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true. The if statement is written with the if keyword, followed by a condition in parentheses, with the code to be executed in between curly brackets.
Syntax:
if( condition )
{
// body of the statements;
}
This is a Java program that asks the user to input their age and then checks if they are eligible to vote. If the age is 18 or above, the program prints a message saying "You are Eligible For Vote...".
Here's how the program works:
Overall, this program is a simple example of how to use an if statement in Java to make a decision based on user input.
import java.util.Scanner; public class if_statement { public static void main(String args[]) { int age; System.out.println("Enter Your Age : "); Scanner in = new Scanner(System.in); age=in.nextInt(); if(age>=18) { System.out.println("You are Eligible For Vote..."); } } }
Enter Your Age : 23 You are Eligible For Vote...To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions