0% found this document useful (0 votes)
44 views7 pages

Esquieres Allan Francis M

The document discusses flowcharting, logical operators, relational operators, and if statements in Java, explaining that flowcharts provide a graphical representation of program logic, relational operators compare values, logical operators connect boolean values, and if statements allow for conditional execution based on boolean conditions. Sample flowcharts and Java code are provided to demonstrate these programming concepts.

Uploaded by

Rajiv Paglicawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views7 pages

Esquieres Allan Francis M

The document discusses flowcharting, logical operators, relational operators, and if statements in Java, explaining that flowcharts provide a graphical representation of program logic, relational operators compare values, logical operators connect boolean values, and if statements allow for conditional execution based on boolean conditions. Sample flowcharts and Java code are provided to demonstrate these programming concepts.

Uploaded by

Rajiv Paglicawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Esquieres Allan Francis M.

The importance of Flowcharting ,Logical Operator and


Relational Operators and If- Statement in Java

Objective:

1. Understand the Flow charting in programming


2. Understand logical and relational operators
3. Understand if statement

FLOWCHART:

The first design of flowchart goes back to 1945 which was designed by John Von Neumann.
Unlike an algorithm, Flowchart uses different symbols to design a solution to a problem. It is another
commonly used programming tool. By looking at a Flowchartone can understand the operations and
sequence of operations performed in a system. Flowchart is often considered as a blueprint of a design
used for solving a specific problem.
Advantages of flowchart:

• Flowchart is an excellent way of communicating the logic of a program.


• Easy and efficient to analyze problem using flowchart.
• During program development cycle, the flowchart plays the role of a blueprint, which makes
program development process easier.
• After successful development of a program, it needs continuous timely maintenance during
the course of its operation. The flowchart makes program or system maintenance easier.
• It is easy to convert the flowchart into any programming language code.

Flowchart is diagrammatic /Graphical representation of sequence of steps to solve a problem.


To draw a flowchart following standard symbols are use

Symbol Name Symbol function


Oval Used to represent start and end
of flowchart
Parallelogram Used for input and output
operation
Rectangle Processing: Used for arithmetic
operations and data-
manipulations
Diamond Decision making. Used to
represent the operation in
which there are two/three
alternatives, true and false etc
Arrows Flow line Used to indicate the
flow of logic by connecting
symbols
Circle Page Connector

Off Page Connector

Predefined Process /Function


Used to represent a group of
statements performing one
processing task.
Preprocessor

Operator Meaning Example


+ Addition A+B
- Subtraction A-B
* Multiplication A*B
/ Division A/B
^ Power A^3 for A3
% Reminder A%B

Operator Meaning Example


== Equal to A == B
!= Not equal to A !< B
> Greater than A<B
< Less than A<B
>= Greater than or equal to A < +B
<= Less than or equal to A <+ B

The logical operators are shown next:

Operator Meaning
& AND A<B&B<C
| OR A<B|B<C
^ XOR (exclusive OR) A<B^B<C
|| Short-circuit OR A < B||B < C
&& Short-circuit AND A < B && B < C
! NOT NOT (A >B)

Selection Control Example Meaning


IF ( Condition ) Then IF ( X > 10 ) THEN execute the statement between
… Y=Y+5 THEN and ENDIF
ENDIF ENDIF
IF ( Condition ) Then Y=Y+5 If condition X>10 is True
… ELSE execute the statement between
ELSE Y=Y+8 THEN and ELSE otherwise
….. Z=Z+3 execute the statements
ENDIF ENDIF between ELSE and ENDIF

Selection Control Example Meaning


WHILE (Condition) WHILE Execute the loop as long as the
DO ( X < 10) condition is TRUE
.. DO
.. print x
ENDDO x=x+1
ENDDO

DO DO Execute the loop as long as the


…. print x condition is false
… x=x+1
UNTILL (Condition) UNTILL ( X >10

Sample

Flowchart to find the sum of two numbers

Step-1 Start

Step-2 Input first numbers say A

Step-3 Input second number say B

Step-4 SUM = A + B

Step-5 Display SUM Step-6 Stop


Sample 2

Flowchart to find the smallest of two numbers

Step-1 Start

Step-2 Input two numbers say NUM1,NUM2

Step-3 IF NUM1 < NUM2 THEN

print smallest is NUM1

ELSE

print smallest is NUM2

ENDIF

Step-4 Stop

Sample 3

Step-1 Start

Step-2 Read three numbers say num1,num2, num3

Step-3 if num1>num2 then go to step-5

Step-4 IF num2>num3 THEN print num2 is largest ELSE print num3 is largest ENDIF GO TO Step-6

Step-5 IF num1>num3 THEN print num1 is largest ELSE print num3 is largest ENDIF

Step-6 Stop
Relational and Logical Operators

In the terms relational operator and logical operator, relational refers to the relationships that
values can have with one another, and logical refers to the ways in which true and false values can be
connected together. Since the relational operators produce true or false results, they often work with
the logical operators. For this reason they will be discussed together here.

The outcome of the relational and logical operators is a boolean value.

In Java, all objects can be compared for equality or inequality using = = and !=. However, the
comparison operators, <, >, <=, or >=, can be applied only to those types that support an ordering
relationship. Therefore, all of the relational operators can be applied to all numeric types and to type
char. However, values of type boolean can only be compared for equality or inequality, since the true
and false values are not ordered. For example, true > false has no meaning in Java.

For the logical operators, the operands must be of type boolean, and the result of a logical
operation is of type boolean. The logical operators, &, | , ^, and !, support the basic logical operations
AND, OR, XOR, and NOT, according to the following truth table:

As the table shows, the outcome of an exclusive OR operation is true when exactly one and only
one operand is true.

Here is a program that demonstrates several of the relational and logical operators:

// Demonstrate the relational and logical operators.

class RelLogOps {
public static void main(String args[]) {
int i, j;
boolean b1, b2;

i = 10;
j = 11;
if(i < j) System.out.println("i < j");
if(i <= j) System.out.println("i <= j");
if(i != j) System.out.println("i != j");
if(i == j) System.out.println("this won't execute");
if(i >= j) System.out.println("this won't execute");
if(i > j) System.out.println("this won't execute");

b1 = true;
b2 = false;
if(b1 & b2) System.out.println("this won't execute");
if(!(b1 & b2)) System.out.println("!(b1 & b2) is true");
if(b1 | b2) System.out.println("b1 | b2 is true");
if(b1 ^ b2) System.out.println("b1 ^ b2 is true");
}
}

The output from the program is shown here:


i<j
i <= j
i != j !(b1 & b2) is true
b1 | b2 is true
b1 ^ b2 is true

Activities:

1. By using a BlueJ Application Run the Demontrates program in this Module


2. In the Demonstrate Program create Flow Charting
3. Make 3 Java Program and Draw the Flow Charting of every program you make.

You might also like