/* related posts with thumb nails */

Opearators, Control Structure:

1. What are the operators in Java?

· Arithmetic operators (+,-,*,/,%)

· Relational operators (>, >=, <, <=, ==, !=)

· Logical operators (&&, ||, !)

· Assignment operators (=, +=, -=, *=, /=, %=)

· Bit wise operators (&, |, ^, ~, <<, >>, >>>)

· Other operators (?:, instanceof, concatenation(+), ++, --, . (dot))

2. List math functions of Java.

Function

Action

sin(x)

Returns the sine of the angle x in radians

cos(x)

Returns the cosine of the angle x in radians

tan(x)

Returns the tangent of the angle x in radians

asin(y)

Returns the angle whose sine is y

acos(y)

Returns the angle whose cosine is y

atan(y)

Returns the angle whose tangent is y

atan2(x,y)

Returns the angle whose tangent is x/ y

pow(x,y)

Returns x raised to y (xy)

exp(x)

Returns e raised to x (ex)

log(x)

Returns the natural logarithm of x

sqrt(x)

Returns the square root of x

ceil(x)

Returns the smallest whole number greater than or equal to x

floor(x)

Returns the largest whole number less than or equal to x

rint(x)

Returns the truncated value of x.

round(x)

Returns the integer closest to the argument

abs(a)

Returns the absolute value of a

max(a,b)

Returns the maximum of a and b

min(a,b)

Returns the minimum of a and b

3. List Control structure in Java.

1. Conditional control structure (Branching):

if

if else

if else if

nested if

switch

2. Jumping control structure:

break

Labelled break

continue

Labelled Continue

return

3. Iterative control structure (loops):

for loop

while loop

do while loop

for each (enhanced for) loop

4. What are logical operators?

Logical operators include: AND (&&), OR (||), NOT (!) operators. ‘&&’, ‘||’ operators are used on two operands where as ‘!’ operator is used only on one opeand. Theses operators give us a Boolean result when applied. Following table shows the output for sample expressions.

&&

AND

(2>1)&&(4<2)

true

||

OR

(2>1)||(2<1)

true

!

NOT

!true

false

5. What is ‘break’?

Break quits the control from corresponding iterative loop. Break is valid only in iterative loops and switch.

6. What is ‘labelled break’?

Labelled break quits the control from labeled iterative loop. The need of labelled break arises when we need to stop the execution of outer loop based on the condition written in inner loop.

7. What is ‘continue?

continue moves the control the first statement in the corresponding iterative loop. “continue” is valid only in iterative loops. It omits the statements written after “continue” and restarts the iterative loop.

8. What is ‘labelled continue?

Labelled continue moves the control the first statement in the labelled iterative loop. It omits the statements written after “continue” and restarts the labeled iterative loop.

9. Compare while and do-while control structures.

While loop:

Do while loop:

This is called entry control loop

This is called exit control loop.

While loop gets executed as long as the condition is true

Do-While loop gets executed as long as the condition is true

Condition is evaluated first and then statements.

Statements get executed first and then Condition.

Minimum number of execution in this case is “zero”

Minimum number of execution in this case is “one”

10. What are nested loops?

If a loop is combined within another loop, it is said to be a nested loop. In a nested loop the inner loop gets executed completely for each iteration of the outer loop.

Related Topics:

0 comments:

Post a Comment