Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

public class Main {
    public static void main(String[] args) {
        operate("on");
        operate("off");
        operate("ON");
        operate("Nothing");
        operate("OFF");
        operate("No");
        operate("On");
        operate("OK");
        operate(null);
        operate("Yes");
    }

    public static void operate(String status) {
        // Check for null
        if (status == null) {
            System.out.println("status  cannot be  null.");
            return;
        }
        status = status.toLowerCase();
        switch (status) {
        case "on":
            System.out.println("Turn on");
            break;
        case "off":
            System.out.println("Turn off");
            break;
        default:
            System.out.println("Unknown command");
            break;
        }
    }
}