mardi 18 avril 2017

"If" Statement within an array, Java

I'm using java in Eclipse. I'm not sure if it is called an array, but I have seen it called that before. The program I'm working on is a simple one where you enter text in and the computer responds. When you launch it, it randomly chooses an opening statement. It goes like this:

String responses[] = {
                "unimportant",
                "unimportant",
                "Let's play a game. What do you want to play?." ,
                "unimportant",
                "unimportant"
            };

I labeled most as unimportant because they are long and not what I'm asking about. I'm trying to figure out how to have an if statement detect whether that third option has been chosen. I previously had this area set up as a Random but this cleaner option was suggested to me. Were it the old way, I could do this, but too much of my code now relies on this area. I'm probably missing something obvious, but I can't figure it out.

TL;DR Trying to have an if detect if a certain string has been chosen.




Aucun commentaire:

Enregistrer un commentaire