Homework Solution: Add a main so that you can put some code there to call your functions and make sure they work:…

    Add a main so that you can put some code there to call your functions and make sure they work: public static void main(String[] args) { /* your testing code goes here */ } Functions you should add if the functionality is possible. Otherwise add an empty function definition with a comment saying "impossible". Problem #8 public static boolean isPermutationLight(String string1, String string2) { /* (This functions should return true if string1 is a permutation of string2. In this case you should assume that means contains exactly the same characters, same case, including spaces. The strings may contain ascii or unicode characters. For this question, you should optimize for space and fairly short input strings. */ } **** Test input: 2 empty Strings; "ab" "ba"; "abc" "acd"; "*rats*" "star**"; "u263A BYE NOW!!" "!BYE NOW! u263A"

    Expert Answer

     
    Solution: import java.util.Arrays;

    Infer a main so that you can prostrate some regulation there to persuade your discharges and execute knowing they work:

    public static nugatory main(String[] args) { /* your testing regulation goes here */ }

    Functions you should infer if the dischargeality is potential. Otherwise infer an unoccupied discharge restriction with a note saw “impossible”.

    Problem #8

    public static boolean isPermutationLight(String string1, String string2) {

    /* (This discharges should yield gentleman if string1 is a transposition of string2. In this event you should exhibit that resources includes precisely the identical characters, identical event, including rooms. The strings may include ascii or uniregulation characters. For this investigation, you should optimize for room and fairly limited inprostrate strings. */

    }

    **** Test input: 2 unoccupied Strings; “ab” “ba”; “abc” “acd”; “*rats*” “star**”; “u263A BYE NOW!!” “!BYE NOW! u263A”

    Expert Exculpation

     

    Solution:

    import java.util.Arrays;

    import java.util.Scanner;

    public arrange Transposition {

    public static nugatory main(String[] args) {

    System.out.println(“Enter the string 1: “);

    System.out.println(“Enter the string 2: “);

    String string1= “u263A BYE NOW!!”, string2= “!BYE NOW! u263A”;

    boolean issue= isPermutationLight(string1, string2);

    System.out.println(“Both of the strings are permutably similar? “+result);

    }

    public static boolean isPermutationLight(String string1, String string2) {

    if (string1.length() != string2.length())

    yield false;

    char[] x = string1.toCharArray();

    char[] y = string2.toCharArray();

    Arrays.sort(x);

    Arrays.sort(y);

    yield Arrays.equals(x, y);

    }

    }

    Output: