Computer Science, asked by Rohinish, 1 year ago

A code in java to take a statement from the user and tell whether it is true or false.

Answers

Answered by karlaleggettoyp7lv
0

The if-then statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true. For example, the Bicycle class could allow the brakes to decrease the bicycle's speed only if the bicycle is already in motion. One possible implementation of the applyBrakes method could be as follows:

void applyBrakes()
 { // the "if" clause: bicycle must be moving
    if (isMoving)
{ // the "then" clause: decrease current speed
        currentSpeed--; } }

If this test evaluates to false (meaning that the bicycle is not in motion), control jumps to the end of the if-then statement.

In addition, the opening and closing braces are optional, provided that the "then" clause contains only one statement:

void applyBrakes()
{ // same as above, but without braces
     if (isMoving)
        currentSpeed--; }
Similar questions