You are on page 1of 7

Operators

%- computes the remainder

++ op++ increments op by 1,evaluates to the value of op before it was incremented

++ ++op increments op by 1: after

-- op-- decrements op by 1: before

-- --op decrements op by 1: after

Example:

Int age= 20;

System.out.println(your age is age++); age=20

(your age is ++age); age=21

(your age is age--); age=20

(your age is --age); age=19

&&

&

|| logical OR

| Inclusive OR

For && and &

Exp1 && exp2

Truth Table

X1 X2 RESULT

TRUE TRUE TRUE

TRUE FALSE FALSE

FALSE TRUE FALSE

FALSE FALSE FALSE


For || and |

Truth Table

X1 X2 RESULT

TRUE TRUE TRUE

TRUE FALSE TRUE

FALSE TRUE TRUE

FALSE FALSE FALSE

Example

Int i=0;

Int j=10;

Test=(i<10) || (j++>9);

System.out.println(i); =0

(j); =10

(test); TRUE

Test=(i<10) | (j++>9);

System.out.println(i); =0

(j); =10

(test); TRUE

^ exclusive OR

| LOGICAL NOT

X1 X2 RESULT

TRUE TRUE FALSE


TRUE FALSE TRUE

FALSE TRUE TRUE

FALSE FALSE FALSE

IF STATEMENTS

Syntax: if (test_expression)

Statement 1;

Statement 2:

Example:

Int a= 20, b= 30;

If(b>a)

System.out.println(b is greater);

}
Flowchart

Start

T Exp F

Statement Stop

IF ELSE STATEMENTS

Syntax: if (text_expression)

Statement1;

Else

Statement2;

}
Flowchart

Start

T Exp F F

Execute if Execute else


branch branch

Stop

ELSE IF

Syntax:

If (test_expression)

Statement1;

Else if (tes_expression)

Statement2;

Else

Statement 3
}

Nested Ifs

Syntax:

Syntax:

If (test_expression_1)

If(nested_expression_1)

Satement 1

Else

Statement2;

1. Write a program to determine the flow regime of a fluid. Input is the Reynolds number no.
2. Create a java program that will determine the largest value. Print the largest value with
identifying message. Input two numbers only.
1.

2.

You might also like