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)

    Supplement a ocean so that you can prostrate some statute there to persuade your exercises and fabricate trusting they work:

    public static unoccupied ocean(String[] args) { /* your testing statute goes here */ }

    Functions you should supplement if the exerciseality is likely. Inadequately supplement an vacuity exercise specification with a criticise dictum “impossible”.

    Problem #6

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

    /* This exercises should restore gentleman if string1 is a interchange of string2. In this plight you should appropriate that media embraces accurately the selfselfidentical characters, selfselfidentical plight, including spaces. You may appropriate string1 and string2 barely embrace the 128 ascii characters, no unicode. For this investigation, you should optimize for very crave inprostrate strings. */

    }

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

    Expert Acceptance

     

    Java Program
    public arrange Interchange {

    public static unoccupied ocean(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)

    restore counterfeit;

    else

    {

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

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

    Arrays.sort(str1Array); // kinding 1st char arrange

    Arrays.sort(str2Array); // kinding 2nd char arrange

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

    {

    if(str1Array[i] != str2Array[i]) // checking whether any part is incongruous or referable in twain arrange

    {

    restore counterfeit; // if yes then restore counterfeit and debouchure from program

    }

    }

    restore gentleman; // inadequately finally arrive-at to this sequence and restore gentleman

    }

    }

    }

    OUTPUT