in java code Write a method getRandString to generate a ran

in java code

/* Write a method getRandString to generate a random String of length

provided in the parameter.*/

static String getRandString(int length) {

/* Write your code here */

}

/* Write a recursive method to print all the Strings separated by lines.

This method cannot contain any loop (that is, uses of for, while, do while

are prohibited). */

public static void printMyList(StringNode M){

/* Write your code here */

}

Solution

/* Write a method getRandString to generate a random String of length
    provided in the parameter.*/
    static String getRandString(int length) {
    /* Write your code here */
        String[] letters = {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}
        String output = \"\";
        for (int i = 0; i < length; i++) {
            //edgarr: check last character \"Z\", make sure it is used
            output = output + letters[int(Math.random() * 25)];
        }
        return output;
    }
    /* Write a recursive method to print all the Strings separated by lines.
    This method cannot contain any loop (that is, uses of for, while, do while
    are prohibited). */
    public static void printMyList(StringNode M){
    /* Write your code here */
        if (M == null) {
            return;
        }
        System.out.println(M.head);
        printMyList(M.next);

    }

in java code /* Write a method getRandString to generate a random String of length provided in the parameter.*/ static String getRandString(int length) { /* Wri

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site