Decision-making:

By: aathishankaran Emailed: 1700 times Printed: 2205 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)
The Basic Structure of a Simple Java program
Recursion in java
Abstract classes in Java
Text to Speech conversion program in Java
Read from a COM port using Java program
Vector example in Java
Connect to a password protected URL from Java program
Student marks calculation program in Java
Integer: byte, short, int, and long data types in Java
wait(), notify() and notifyAll() in Java - A tutorial
Increment and Decrement Operator
Calculate gross salary in Java
XML and Java - Parsing XML using Java Tutorial
Count number of vowels, consonants and digits in a String in Java
Most Emailed Articles (in Java)
TreeMap example in Java
Integer: byte, short, int, and long data types in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java program to print prime numbers using Thread
Bubble Sort in Java
emulator 0 terminated while waiting for it to register!
Java program for Map
History of Java
Creating Users and Passwords with Tomcat using tomcat-users.xml
What is a report design in JasperReports?
What is UTF-8?
java.lang.reflect package
CharSequence Interface in Java
The if-then-else Statement in Java