Search the courses, subjects, tracks, games and features, or jump straight to a page.
5 cards from this section. Quick, good the night before a test.
What is a unary operator? Name the five unary operators covered in this lesson.
"Uni" means one: count how many values the operator needs.
Predict what this program prints, then run it to check: int n = 10; followed by n++;, n++;, n--; and a print of n.
Write down the value of n after each line.
What does int a = 5; System.out.println(a++); print?
Postfix means use first, change later.
What is the value of x after int x = 5; x = x++;?
Look at which value the assignment receives.
Write a game-state program. A player starts with a score of 0, 3 lives and the game not paused. Simulate these events and print the state after each one: collect a coin; collect a second coin while printing the score with postfix; collect a bonus coin while printing the score with prefix; get hit once; press pause twice. Finally, print whether the game is over using !.
Use score++ and ++score inside println to see the difference, lives-- for a hit and paused = !paused for the pause button.
Predict, then verify. With int i = 1;, what are j and i after int j = i++ + i++ * --i;? Write out your trace, confirm it with a program, and then rewrite the expression as separate, easy-to-read statements that give the same result.
Operands are read left to right and each ++ or -- applies immediately, but * is still done before +.
6 more questions in this section. Enroll free to practise them all.
Enroll free