//If Statement:-
- //In java, an if statement is used when we want to test a condition.
- //the condition after evaluation of if statement will be either true or false.
- //If this condition is true then the block of the statement connected to the if statement is executed.
- //If this condition is false then the block of the statement connected to the if statement is not executed.
- Syntax of if statement :-
if (condition)
{
// block of code to
be executed if the condition is true
}
====================================================================
//Program I:-
package controlStatements;
public class IfUse
{
public static void main(String[] args)
{
//If
my marks is greater than 40 then Print I Am Pass.
int marks=64;
if(marks>40)
{
System.out.println("I Am Pass");
}
}
}
//Output:-
I Am
Pass
====================================================================
//Program
II:-
package controlStatements;
public class IfUse
{
public static void main(String[] args)
{
//If my marks is greater than 40 then Print I Am Pass.
int marks=4;
if(marks>40)
{
System.out.println("I Am Pass");
}
}
}
//Output:-
====================================================================
//Program
III:-
package controlStatements;
public class IfUse
{
public static void main(String[] args)
{
//If it is Sunday then Print Today is Holiday.
String day="Sunday";
if(day=="Monday")
{
System.out.println("Today is Holiday");
}
}
}
//Output:-
====================================================================
//Program
IV:-
package controlStatements;
public class IfUse
{
public static void main(String[] args)
{
//If it is Sunday then Print Today is Holiday.
String day="Sunday";
if(day=="Sunday")
{
System.out.println("Today is Holiday");
}
}
}
//Output:-
Today is Holiday
====================================================================
0 Comments