-7
 else if (userChose == "1")
   {
      if (compChose == "2")
      {
         System.out.println("You Win!");
      {

      else 
      {
         (compChose == "3");
         System.out.println("You lose!");
      {
   }

It keeps saying that this code for every example is not a sentence? compChose == "3";

OhioState
  • 21
  • 3
  • also my variables are correct compChose and userChose. I established them at the beginning. I just didn't add that because I am only getting 8 errors and it's part of this. – OhioState Oct 12 '18 at 19:43
  • What is `compChose`? Please provide an [MCVE] – GBlodgett Oct 12 '18 at 19:44
  • 2
    `(compChose == "3");` is not a valid statement. – shmosel Oct 12 '18 at 19:44
  • 3
    Also, all your conditional logic will fail, because that's not [how you compare strings in Java](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java). – azurefrog Oct 12 '18 at 19:44
  • 1
    It is right, `compChose == "3";` is not a statement, it's an expression. Perhaps you meant `if (compChose == "3")`? – Andreas Oct 12 '18 at 19:45
  • 2
    Why does your code have 5 `{` start-braces and only 1 `}` end-brace? – Andreas Oct 12 '18 at 19:46
  • Im not comparing strings? Im comparing the button they will press from jbutton 1, 2, or 3.... int userChose, compChose; – OhioState Oct 12 '18 at 19:46
  • 1
    @OhioState When you enclose them in quotation marks they become `String`'s – GBlodgett Oct 12 '18 at 19:47
  • @OhioState Then change `if (compChose == "2")` to `if (compChose == 2)` – Andreas Oct 12 '18 at 19:47
  • @Andreas maybe that's what i mean? Idk im a little confused and our teacher doesn't help. userChose = userPick(); compChose = computerPick(); winner = determineWinner(userChose, compChose); – OhioState Oct 12 '18 at 19:47
  • @GBlodgett shitt I knew that didnt look right. Im sorry. I'm flustered. I think Im overthinking my section. Its hard only doing a section of a code. I would have rather done the whole project myself – OhioState Oct 12 '18 at 19:48
  • Okay so it compiles now! Although, I feel like it doesn't look right because I have a ton of if statements within the main if else – OhioState Oct 12 '18 at 19:58

1 Answers1

0

You should compare strings in java using the equals-method that comes with these String-objects. Here's an example:

string1 = "This is a text";
string2 = "This is a text";
System.out.println(string1.equals(string2));

The result would be true.

I also recommend looking into switch-statements if you are going to have a lot of if-statements to check for user input. I hope this helps!

Nystuen
  • 35
  • 5
  • Thank you so much!! I was getting my strings and integer methods switched up. I did see switch statements in my textbook but the teacher said she didn't like those. I thought it would look nicer/easier. Thank you all for the help!! – OhioState Oct 12 '18 at 19:54
  • @OhioState I am glad to help! I got no idea why people are downvoting my answer, but you could upvote the answer and accept it as a solution to your problem? :) – Nystuen Oct 12 '18 at 19:57
  • 3
    @OhioState [You said](https://stackoverflow.com/questions/52786065/we-are-doing-groups-in-creating-rock-paper-scissors-we-are-using-1-for-rock/52786122#comment92493645_52786065) `userChose` is an `int`. Are you now saying it's a `String`? If so, [azurefrog already told you](https://stackoverflow.com/questions/52786065/we-are-doing-groups-in-creating-rock-paper-scissors-we-are-using-1-for-rock/52786122#comment92493598_52786065) how to compare strings. – Andreas Oct 12 '18 at 20:00
  • 1
    @Nystuen If the problem is that variables are `String` variables, even though OP said they were `int` variables, and that solution is to call `equals()`, then question should be closed as duplicate of [How do I compare strings in Java?](https://stackoverflow.com/q/513832/5221149), and it shouldn't be answered, which I believe is why this answer has been down-voted. In an attempt to keep StackOverflow clean, we don't want a lot of redundant answers. – Andreas Oct 12 '18 at 20:15
  • @Andreas Thank you very much for clarifying! – Nystuen Oct 12 '18 at 20:44
  • its an int. I didnt mean to try to compare strings. Sorry for this bad question guys. I was very confused myself – OhioState Oct 13 '18 at 16:31