Decision-making:

By: aathishankaran Emailed: 1697 times Printed: 2202 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 )
How to Send SMS using Java Program (full code sample included)
Student marks calculation program in Java
XML and Java - Parsing XML using Java Tutorial
append() in Java
How to use ArrayList in Java
Garbage collection and Finalize() method
Using StringTokenizer in Java
Abstract classes in Java
Increment and Decrement Operator
Read from a COM port using Java program
Count number of vowels, consonants and digits in a String in Java
Integer: byte, short, int, and long data types in Java
indexOf( ) and lastIndexOf( ) in Java
Using toLowerCase( ) and toUpperCase( ) in Java
The Basic Structure of a Simple Java program
Most Emailed Articles (in Java)
How to use ArrayList in Java
Write to a COM port using Java program
Read from a COM port using Java program
How to access instance from an inner class and accessing outer class variables in java
Data Types in Java
Tomcat and httpd configured in port 8080 and 80
Save/Write/Read image file from/to a database using Java program
Java program for changeable wrapper class
History of Java
Method Overloading (function overloading) in Java
Sample Java program shows how to write to COM port using Java.
Sample program to demonstrate the use of ActionListener
Introducing JavaScript.
Assigning Object Reference Variables
Bitwise Operator Assignments