Decision-making:

By: aathishankaran Emailed: 1728 times Printed: 2329 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Decision-making: The if construct

 

If a certain condition is true, you direct the program to take one course of action. If the condition is false, you direct the program to do something else. This is one of the most fundamental concepts in computer programming. This decision-making can be done by means of the if construct. The if construct makes use of relational and logical operators for decision-making. The simplest form of if construct is as follows:

 

if (condition)

{

            statement 1;

            statement 2;

}

 

Example:

 

To accept two numbers and verify and whether they are equal or not, the following pseudocode can be witten:

 

PROGRAM_EQUAL

{

            integer Number1;

            integer Number2;

            accept Number1;

            accept Number2;

            if(Number1 == Number2)

            {

                        display “Input numbers are equal”;

            }

}

 

If the numbers are equal, it displays the message “Input numbers are equal.”. If the are not equal, the execution of program sequence terminates without any message. To handle the situation when two numbers are not equal, the following pseudocode can be written as:

 

PROGRAM_EQUAL

{

            integer Number1, Number2;

            accept Number1;

            accept Number2;

            if(Number1 == Number2)

            {

                        display “Input numbers are equal.”;

            }

            else

            {

                        display ”Input numbers are not equal.”;

            }

}

 

The general form of if construct is as follows:

 

If( condition )

{

            statement1;

            statement2;

}

else

{

            statement3;

            statement4;

}

 


Java Home | All Java Tutorials | Latest Java Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java File
Java String
Count number of vowels, consonants and digits in a String in Java
Reverse a number in Java
Student marks calculation program in Java
Handling Fractions in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Multiple Inheritance sample in Java
Java program using Method Overriding
Java program to check if user input is an even number

More Latest News
Most Viewed Articles (in Java )
Method Overloading (function overloading) in Java
XML and Java - Parsing XML using Java Tutorial
How to Send SMS using Java Program (full code sample included)
FileReader and FileWriter example program in Java
Vector example in Java
Method Overriding in Java
What is Java?
Stack example in Java - push(), pop(), empty(), search()
Read from a COM port using Java program
The Basic Structure of a Simple Java program
arraycopy example in Java
append() in Java
Calendar - sample program in Java
for loop in java
How to use ArrayList in Java
Most Emailed Articles (in Java)
Applet Notinited : Applet xxxxxxxxxxxx notinited
Basics of Exception Handling in Java
Tomcat and httpd configured in port 8080 and 80
Calculate average sale of the week in Java
Vector in Java - Sample Program
LinkedList in Java
Taking the size of an Array at runtime & generate random numbers to populate the Array
Getting Started with Java
Configuring a DataSource in Tomcat
What is JasperReports?
java.lang.reflect package
instanceof operator example in Java
The Unary Operators example in Java
Operator Precedence in Java
toRadians() and toDegrees() Sample program in Java