Home Java Jdk7 Decision-making Statements in java 7

Related Tutorials


 
 

Share on Google+Share on Google+

Decision-making Statements in java 7

Advertisement
In this section, we will discuss about Decision-making Statements in java 7. This is one type of control flow statement.

Decision-making Statements in java 7

In this section, we will discuss about Decision-making Statements in java 7. This is one type of control flow statement.

Decision-making Statements :

This kind of control statements is used where you need to take any decision under certain conditions. We write some statements under that condition. Following are the statements which comes under Decision making-

  • If statement
  • switch statement
  • conditional operator statement.

If Statement :

If statement is one of the basic control flow statements. It checks the condition written in if and if condition is satisfied then it executes the block of statements. Otherwise it jumps out of the block. You can also write else part of if by using keyword else.

Syntax :

if(condition)
{.............
statements...
}
else{
.......... statements
}

You can also use multiple if Statement that means you can use nested if-else statements.

Switch Statement :

Switch statement is another decision-making statement used to control the flow of program. Like if-else statements, switch statement holds many conditions to execute. It contains many cases and execute one of them according to the tested variable.

Syntax :

switch(expression){
case value1 : statements.....
                       break;

case value2 : statements.....
                       break;
.
.
.
case value n : statements.....
                       break;
default : statements....
              break;
}

Conditional Operator Statement :

Conditional operator is also known as ternary operator. It checks the condition if true then expression first executes otherwise the second expression executes.
It uses 2 operators (? and :) and 3 operands.

Syntax :

condition ? expression1 : expression2

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 22, 2012

Related Tutorials

Discuss: Decision-making Statements in java 7  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com