Determining the Winner of the Round

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

Yes, but this would add more logic to the program. You might want to do this as an exercise.

Determining the Winner of the Round

The final code in the loop body determines the winner of the round:

// Determine Winner of Round and Adjust Scores
if ( playerToss > compToss )
{
  playerScore = playerScore+1;
  System.out.println("You win the round!");
}
else
{
  compScore = compScore+1;
  System.out.println("You loose the round!");
}      
System.out.println("Score: computer " + compScore + ", you " + playerScore + "/n");

There is nothing difficult here, but notice that the code is written so that the computer wins when the dice tosses are equal.

QUESTION 22:

As another exercise, you could add code to do something else when the tosses are equal.