JAVA 49
TestAndOr By admin on 23rd September 2021 05:15:32 AM
  1. //demonstrates AND/OR skipovers in a toggle "false && true || true"
  2. public class TestAndOr {
  3.     //set the starting value of the light to true or false
  4.     public static boolean lightIsOn = false;
  5.     //main program
  6.     public static void main(String[] args) {
  7.         //print out the status of the light before toggling
  8.         System.out.println("The light is " + lightIsOn);
  9.         //perform the toggle of the light.
  10.         //if lightIsOn is false, it breaks the AND and jumps straight to the rest of the OR.
  11.         //if lightIsOn is true, it continues the AND and ignores the rest of the OR.
  12.         if (((lightIsOn) && turnOffLight()) || turnOnLight()) {
  13.             //everything happens in the condition so this is empty
  14.         }
  15.         //print out the status of the light after toggling
  16.         System.out.println("The light is " + lightIsOn);
  17.     }
  18.     //function executed in main statement when light is on
  19.     public static boolean turnOffLight(){
  20.         lightIsOn = false;
  21.         return true;
  22.     }
  23.     //function executed in main statement when light is off
  24.     public static boolean turnOnLight(){
  25.         lightIsOn = true;
  26.         return true;
  27.     }
  28. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.