samedi 29 février 2020

How do I store each of these sysouts in an if else statment into one solution string

this project is for a game called Mastermind. I need to create a randomly generated string and store it to a solution so I can later test the solution string to see if the user has entered the correct order. Ive successfully created the generator to output but I don't know how I am going to get it to the String solution variable. We are not allowed to use arrays for this assignment.

    public void makeSolution() {
    int randNum;
    Random randGen = new Random();

    for(int i = 0; i < NUM_OF_PEGS; i++) {
        randNum = randGen.nextInt(6);
        if(randNum == 0){
            System.out.print("Y");

        }
        else if(randNum == 1) {
            System.out.print("O");

        }
        else if(randNum == 2) {
            System.out.print("R");

        }
        else if(randNum == 3) {
            System.out.print("B");

        }
        else if(randNum == 4) {
            System.out.print("G");

        }
        else if(randNum == 5) {
            System.out.print("P");
        }
    }

}

Aucun commentaire:

Enregistrer un commentaire