-3

The following code does not show any errors, however, when I tried to input user play, I get tons of errors.

public static void rockPaperScissors(Scanner input) {
    // TODO Auto-generated method stub
    String user = null, computer = null;
    int computerRand;
    Random num = new Random();
    System.out.println("Lets play Rock, Paper, Scissors.\nPlease enter a move\n");
    computerRand=num.nextInt(3)+1;

    if (computerRand==1)
        computer="R";
    else if (computerRand==2)
        computer="P";
    else if (computerRand==3)
        computer="S";

    System.out.println("Enter user play");
    user=input.nextLine();

    if (user==computer){
        System.out.println("Tie. Try over!");
        }
    else if (user==("R")){
        if (computer==("S"))
            System.out.println("Rock beats Scissors. You win!");
    else if (computer==("P"))
            System.out.println("Paper covers rock. CPU wins..");
    }
    else if (user==("P")){
        if (computer==("S"))
            System.out.println("Scissors cut paper. CPU wins..");
    else if (computer==("R"))
            System.out.println("Paper covers rock. You win!");
    }
    else if (user==("S")){
        if (computer==("P"))
            System.out.println("Scissors cuts paper. You win!");
    else if (computer==("R"))
            System.out.println("Rock beats scissors. CPU wins..");
    }

            System.out.println("Computer play is: "+computer);

}
iRaySpace
  • 65
  • 8
squash69
  • 5
  • 6
  • yeah everyone down vote this when i really need help. psh. people these days. – squash69 Apr 01 '15 at 02:54
  • 1
    If you really want help, meet people 1/2 way. First of all, edit your post and indent your code so it is all formatted properly in the code block. Then try to narrow it down to some specific questions, and see this: [How to Ask](http://stackoverflow.com/review). You're not a victim. People here see thousands of questions and most of them are *not* voted down. If yours is voted down, it is for a reason. Consider learning an effective way to ask for help you need and try not to ask overly broad questions. – clearlight Apr 01 '15 at 02:58
  • i'm sorry this is my 5th post and i didn't know the box wouldn't fit it all. and indent it? looks pretty lined up to me – squash69 Apr 01 '15 at 03:02
  • The best way to get good answers and up-votes is to ask a decent question, and yours is not quite. You post code and mention "errors", but you never tell us specifically what errors you're seeing, what lines are causing the errors. Also you only give us one brief line of explanation. So if you really need good help, put in the effort to write a good question. The help links on this site are for just that. It's always a good idea to follow what I call "the questioner's golden rule": put in as much effort into asking your question as you'd like a volunteer to expend in answering it. – Hovercraft Full Of Eels Apr 01 '15 at 03:06
  • It doesn't show which lines have errors. like i said at the top it doesn't have them before i run it just after i run it and when i try to enter the users turn and i don't know what they mean. first semester in programming give me a little break man. – squash69 Apr 01 '15 at 03:09
  • Again, post the errors any errors or issues you see here for us to see. **Describe** in detail what misbehaviors you're experiencing. I'm trying to "give you a break" but please rather than complain, please read the [help] sections, that's what they're for. Your question is again one single short line of explanation and a code dump. Honestly it's a lazy question, and you're complaining that we're not working hard enough for you. Just a little effort into your question will pay great dividends. Really. – Hovercraft Full Of Eels Apr 01 '15 at 03:11
  • Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:840) at java.util.Scanner.next(Scanner.java:1461) at java.util.Scanner.nextInt(Scanner.java:2091) at java.util.Scanner.nextInt(Scanner.java:2050) at labThree.dispMenu(labThree.java:48) at labThree.main(labThree.java:16) – squash69 Apr 01 '15 at 03:17
  • These are the errors it gives me. i don't know what they mean. sorry to be rude about it. – squash69 Apr 01 '15 at 03:18
  • 1
    You want everyone to see that so much better to edit your post and include it up there, and consider what Hovercraft Full of Eels is saying. He's not steering you wrong. Have a look at the [review](http://stackoverflow.com/review) queue, and you can get an idea about what questions are good and which are less effective. People here are encouraged to help moderate the forum and get a lot of exposure and can see what works and what doesn't. – clearlight Apr 01 '15 at 03:27
  • alright man. my bad i don't know how to use this site. i am taking yalls responses seriously but i can't get this program working and it is homework due tomorrow. Just trying to see if anyone knew what was wrong and could steer me in the right direction. not looking for handouts here. – squash69 Apr 01 '15 at 03:36

1 Answers1

1
  "else if (user==("R")){"

here you are comparing strings with '==' this is not good i think trying

(user.equals("R")) 

would help.

checkout this question

Community
  • 1
  • 1
Anuswadh
  • 542
  • 1
  • 11
  • 19