GuidePedia

0



if statement in java.



If  statement is a keyword in java programming.if  statement is a decision-making statement in java programming.it is the simplest form of the selection constructs. It is used to execute and skip the statement a set of a statement by checking condition. The condition is given as relational expression. If the condition is true the statement a set of statements execute after the if statement is executed.if condition is false the statement or set of statement after if  statement is executed. The preceding program displays a message such as 6+2 is false if you choose these answers it is wrong. You have used the selection statement to carry out the minor change. This section introduced selection statement.java has several types of selection statement but on this page, we study one way of the if statement. 

















Syntax of if statement.

If(condtion)
{
Statement..1
Statement..2
Statement..3
}

Example.


If (radius>=0){
Area= radius*radius+pi
System.out.printin(“the area for the circle of radius “ +radius “is” area);}

Flowchart





















Limitation of if statement.
If  statement is the simple selection structure but it is very limited in its use.
The statement or set of statement is executed if  condition is true but if the condition is the false the nothing is happening.
A user may went for
Execute one statement or set of statement if the condition is true.
Execute the other statement and set of statement if the condition is false.





















For example






Imort java.until.Scanner;
Public class SimpleDemo{
Public static void main(string[]args)
{
Scanner input= new scanner(system.in);
System.out.printin(“enter an integers:”);
Int number=input.nextint();
If(number%5==0)
System.out,printin(“hifive”)
If(number%2==0)
System.out.printin(“hieven”);
}}

Output








Post a Comment

THANKS FOR COMMENT

 
Top