フリー問題

Java SE 17 Developer のフリー問題 3 / 20 問目

問題文

A reporting method computes a percentage with the single line int percent = count * 100 / total; where count holds 3 and total holds 8. Which statement describes the value that percent receives and the reason?

選択肢

  1. The variable receives 0, because the division binds more tightly than the multiplication, so 3 divided by 8 is evaluated as the first step
  2. The line fails to compile, because the whole expression is promoted to double and an explicit cast back to int is required for the assignment
  3. The variable receives 37, because the multiplication runs first and the division that follows works on two int values and drops the fraction of 37.5
  4. The variable receives 38, because an int division rounds the exact quotient of 37.5 to the nearest whole number before the assignment takes place

解答・解説を確認するには

正解と解説の確認、回答の記録には無料登録が必要です。登録すると演習モードでフリー問題に回答し、正誤と解説をその場で確認できます。