Note that there are some explanatory texts on larger screens.

plurals
  1. POA more efficient way that takes less space? this is a method btw
    primarykey
    data
    text
    <p>Here's part of a code for a Rock Paper Scissors project and im just wondering if there is a way to do this that takes up less space. Preferably more efficient too. Basically this is a method and what this method does is compare user inputs to see if one side beats the other. Thanks.</p> <pre><code>public String determineWinner() { String winner = "yolo"; //if fail if(compChoice.equals("S") &amp;&amp; (playChoice.equals("s"))) { winner = "nobody. There was a tie because you guessed the same thing."; } if(compChoice.equals("P") &amp;&amp; (playChoice.equals("p"))) { winner = "nobody. There was a tie because you guessed the same thing."; } if(compChoice.equals("R") &amp;&amp; (playChoice.equals("r"))) { winner = "nobody. There was a tie because you guessed the same thing."; } if(compChoice.equals(playChoice)) //R R, R P, R S { winner = "nobody. There was a tie because you guessed the same thing."; } if(compChoice.equals("R") &amp;&amp; (playChoice.equals("P") || playChoice.equals("p"))) //R P { winner = "player because Paper beats Rock."; } if(compChoice.equals("R") &amp;&amp; (playChoice.equals("S") || playChoice.equals("s"))) //R S { winner = "computer because Rock beats Scissors."; } if(compChoice.equals("P") &amp;&amp; (playChoice.equals("R") || playChoice.equals("r")))//P R { winner = "computer because Paper beats Rock."; } if(compChoice.equals("P") &amp;&amp; (playChoice.equals("S") || playChoice.equals("s")))//P S { winner = "player because Scissors beats Paper."; } if(compChoice.equals("S") &amp;&amp; (playChoice.equals("R") || playChoice.equals("r"))) //S R { winner = "player because Rock beats Scissors."; } if(compChoice.equals("S") &amp;&amp; (playChoice.equals("P") || playChoice.equals("p"))) //S P { winner = "computer because Scissors beats Paper."; } return winner; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload