(SOLVED) IsTwin.java

Write an “isTwin(a, b)” method that returns true if a and b are twins and returns false if they are not. a and b are two strings

// Class de test (Main)

public class IsTwin {

    public static void main(String[] args) {

	System.out.println(Solution.isTwin("Hello", "world")); // false
	System.out.println(Solution.isTwin("acb", "bca")); // true
	System.out.println(Solution.isTwin("Lookout", "Outlook")); // true

// Class Solution 

class Solution {
    public static boolean isTwin(String a, String b) {
	    char[] first = a.toLowerCase().toCharArray();
	    char[] second = b.toLowerCase().toCharArray();
    return Arrays.equals(first, second);

Marwen Mselmi
Author: Marwen Mselmi

Founder of Javatuto.com, love Java and open source stuff. Follow me on Linkedin.

Leave a comment