Given the code fragment:
Which modification enables the code to print 54321?
A. Replace line 6 with System, out. print (–x) ;
B. At line 1, insert x –;
C. Replace line 6 with –x; and, at line 7, insert system, out. print (x);
D. Replace line 12 With return (x > 0) ? false: true;
B
public static void main(String[] args) {
int x = 5;
while (isAvailable(x)) {
System.out.print(x);
x–;
}
}
static Boolean isAvailable(int x){
return x–>0 ? true :false;
}
The answer is B: At line 7, insert x – -;
actually the correct answer is at line 7, insert x–; then option B is correct
its B.
A is the closest, but it should be Replace line 6 with System, out. print (x–) ;