QUESTION IMAGE
Question
int a = 5 - 1;
int b = a - 1;
int c = a % b;
what is the output of the following code fragment?
system.out.println(a + \ \ + b + \ \ + c);
options: 4 4 1, 4 3 1, 4 3 0
Step1: Calculate the value of a
Given \( \text{int } a = 5 - 1 \), so \( a = 4 \).
Step2: Calculate the value of b
Given \( \text{int } b = a - 1 \), substitute \( a = 4 \), we get \( b = 4 - 1 = 3 \).
Step3: Calculate the value of c
The operator % is the modulus operator, which gives the remainder of the division. So \( \text{int } c = a \% b \), substitute \( a = 4 \) and \( b = 3 \), we have \( 4\div3 \) gives a quotient of 1 and a remainder of 1, so \( c = 1 \).
Step4: Determine the output
Now we need to print \( a + " " + b + " " + c \), substituting the values of \( a = 4 \), \( b = 3 \), \( c = 1 \), the output is \( 4\ 3\ 1 \).
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
B. 4 3 1