056.
057.
What happens when you execute the code below? If it
compiles, what will be the output?
int iValue1 = 100;
int iValue2 = 200;
boolean isTrue() {
return true;
}
if(((iValue1 > iValue2) && (iValue2 < 50))
|| isTrue()) { //Line 1
System.out.println(“This is True”);
}
else {
System.out.println(“This is False”);
}
Answer:
The code compiles fine and displays the following output:
This is True
The if statement at Line 1 uses an OR operation. An OR
operation returns true when any one of its operands is true. Since
the isTrue() method
returns a true, the if statement will return
a true. So irrespective of the result of the AND operation, the
expression within the If statement returns a true.
What is the use of “break” and “continue” statements?
Answer:
The
break keyword can be used within a loop.
When the break
statement is encountered, the loop is immediately terminated and
058.
059.
control is transferred outside the loop.
The
continue keyword can also be used within a loop. It is used
to stop executing the next statement
in the loop for the current
iteration and transfer control to the start of the loop.
Do'stlaringiz bilan baham: