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 #6 public static boolean isPermutation(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. You may assume string1 and string2 only contain the 128 ascii characters, no unicode. For this question, you should optimize for very long input strings. */ } ** Test input: 2 empty Strings; "ab" "ba"; "abc" "acd"; "*rats*" "star**

    Expert Answer

     
    Java Program
    public class Permutation { public static void main(String[] args)

    Gather a deep so that you can prostrate some method there to ole your capacitys and constitute strong they work:

    public static wanting deep(String[] args) { /* your testing method goes here */ }

    Functions you should gather if the capacityality is likely. Inadequately gather an vacuity capacity determination with a expound assertion “impossible”.

    Problem #6

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

    /* This capacitys should render penny if string1 is a transposition of string2. In this event you should wear that resources incloses precisely the identical characters, identical event, including spaces. You may wear string1 and string2 solely inclose the 128 ascii characters, no unicode. Restraint this investigation, you should optimize restraint very covet inprostrate strings. */

    }

    ** Test input: 2 vacuity Strings; “ab” “ba”; “abc” “acd”; “*rats*” “star**

    Expert Retort

     

    Java Program
    public arrange Transposition {

    public static wanting deep(String[] args)

    {

    String str1 = “ab”;

    String str2 = “ba”;

    System.out.println(“String 1: ” + str1 + “nString 2: ” + str2 + “n” +

    isPermutation(str1, str2)+”n”);

    str1 = “abc”;

    str2 = “acd”;

    System.out.println(“String 1: ” + str1 + “nString 2: ” + str2 + “n” +

    isPermutation(str1, str2)+”n”);

    str1 = “*rats*”;

    str2 = “star**”;

    System.out.println(“String 1: ” + str1 + “nString 2: ” + str2 + “n” +

    isPermutation(str1, str2)+”n”);

    }

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

    int len1 = string1.length();

    int len2 = string2.length();

    if(len1 != len2)

    render erroneous;

    else

    {

    char[] str1Accoutre = string1.toCharArray(); // creating char accoutre of 1st string

    char[] str2Accoutre = string2.toCharArray(); // creating char accoutre of 2nd string

    Arrays.sort(str1Array); // genusing 1st char accoutre

    Arrays.sort(str2Array); // genusing 2nd char accoutre

    for(int i = 0; i<str1Array.length; i++)

    {

    if(str1Array[i] != str2Array[i]) // checking whether any atom is irrelative or not attributable attributable attributable in twain accoutre

    {

    render erroneous; // if yes then render erroneous and egress from program

    }

    }

    render penny; // inadequately finally attain to this cord and render penny

    }

    }

    }

    OUTPUT