Java - Write code to compare two string for equality using nested if statements

Requirements

Write code to compare two string for equality using nested if statements

Check reference and verify null value.

Hint

Use nested if statements.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String l = "book2s.com";
        String r = "book2s.com";
        System.out.println(equals(l, r));
    }/*from   www.j av a 2s .com*/

    public static boolean equals(String l, String r) {
        if (l != r) {
            if (l != null || r != null) {
                return l.equals(r);
            }
            return false;
        }
        return true;
    }
}

Related Exercise