0

I am doing a "Rock,Paper,Scissors" game with Java and I have a question, is there any way to create and Array with answers and check if any of these values equal to another array? For example:

Here is the answerArray (also I want to have short cuts for answers):

String[] answersArray = {"Rock","R","Paper","P","Scissors","S"};

And here is a randomArray for computer:

String[] npcAnswer = {"Rock","Paper","Scissors"};
        int idx = new Random().nextInt(npcAnswer.length);
        String npcRandomAnswer = (npcAnswer[idx]);

So, I want to check through the scanner if my answer (answersArray) equal to npcRandomAnswer.

Sorry if I have grammar mistakes, I did my best to explain my point.

Thank you.

John E.
  • 321
  • 4
  • 11
  • I think you may benefit from using a `HashMap` instead of an array – blurfus Feb 24 '16 at 00:39
  • @ochi hm... my java skills are limited for now, that's why I am asking about arrays, but I will definitely google HashMap, thank you! – John E. Feb 24 '16 at 00:40
  • You can change the question title to "false" or explain what do you mean. You want to search for the string in the array, maybe? Though even that doesn't make sense in your example, as that will always be true – Gavriel Feb 24 '16 at 00:40
  • @Gavriel basically I want to check if answerArray = to npcRandomAnswer – John E. Feb 24 '16 at 00:42
  • @S.Anthony, I have a pack of gums I'm my left hand, and a gum in my right hand, do I have the same thing in my two hands? – Gavriel Feb 24 '16 at 00:45

1 Answers1

1

You can only compare apples with apples. Or actually you can compare apples with oranges, but then you don't really need to compare them, you know the answer will always be false.

It looks like you don't really know yet what will your algorithm be.

I suggest you to concentrate on the algorithm, write pseudo code, and when you have it, try to make java out of it. If you'll have problem with the java, we can easily help you if you post your algorithm (in a new question)

Gavriel
  • 18,880
  • 12
  • 68
  • 105