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));
    }/*ww  w .  ja  va  2 s .c o m*/

    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