0%
0 / 8 answered
Compound Assignment Operators Practice Test
•8 QuestionsQuestion
1 / 8
Q1
In the game score code below, how does the use of *= affect the value of score?
public class GameScoreDemo {
public static void main(String[] args) {
int score = 10; // starting score
/* Player collects a coin */
score += 5; // add 5 points
// Player hits a trap
score -= 3; // lose 3 points
// Player gets a double-score power-up
score *= 2; // double the score
// Player shares points across 3 rounds
score /= 3; // integer division
System.out.println("Final score: " + score);
}
}
In the game score code below, how does the use of *= affect the value of score?
public class GameScoreDemo {
public static void main(String[] args) {
int score = 10; // starting score
/* Player collects a coin */
score += 5; // add 5 points
// Player hits a trap
score -= 3; // lose 3 points
// Player gets a double-score power-up
score *= 2; // double the score
// Player shares points across 3 rounds
score /= 3; // integer division
System.out.println("Final score: " + score);
}
}