jeudi 3 décembre 2015

Replace Random Number with "X"

I have been tasked to replace a random number in a string with "X." The only way I am allowed to do it is with Math.random. The method also can have no parameters. This is in a class that is used in a separate pre-assembled driver. This is the code I have written:

public ComputerMicrobe mutate()
{
    int a = (int)(Math.random() * (0 - dNACode.length()));
    String b = Integer.toString(a);
    dNACode = dNACode.replace(a, "X");
    return this;

} // End mutate

I am completely lost. Can anyone help?




Aucun commentaire:

Enregistrer un commentaire