public void toggleFirstSwitch() { firstSwitchState = (firstSwitchState == 1) ? (0) : (1); lampState = (lampState == 1) ? (0) : (1); } %3D public void toggleSecondSwitch() { secondSwitchState = (secondSwitchState == 1) ? (0) : (1); lampState } (lampState == 1) ? (0) : (1); %3D

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter1: Creating Java Programs
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question
How would these ternary operators be converted into else/if statements? Please post the code below
public void toggleFirstSwitch () {
firstSwitchState = (firstSwitchState == 1) ? (0) : (1);
lampState = (lampState == 1) ? (0) : (1);
}
public void toggleSecondSwitch() {
secondSwitchState = (secondSwitchState == 1) ? (0) : (1);
lampState
}
(lampState == 1) ? (0) : (1);
%3D
Transcribed Image Text:public void toggleFirstSwitch () { firstSwitchState = (firstSwitchState == 1) ? (0) : (1); lampState = (lampState == 1) ? (0) : (1); } public void toggleSecondSwitch() { secondSwitchState = (secondSwitchState == 1) ? (0) : (1); lampState } (lampState == 1) ? (0) : (1); %3D
Expert Solution
Step 1

If-else statement:

A conditional statement determines whether a specified condition is met or not. A conditional statement performs two operations. If the given condition is true, then the if block is executed, otherwise the else block is not executed.

Syntax:

if(condition)
{
    // if block
}
else
{
    // else block
}

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Database connectivity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT