Which modification enables the code to print 54321?

Given the code fragment: Which modification enables the code to print 54321?

Given the code fragment: Which modification enables the code to print 54321?

A.
Replace line 12 With return (x > 0) ? false: true;

B.
Replace line 6 with –x; and, at line 7, insert system, out. print (x);

C.
Replace line 6 with System, out. print (–x) ;

D.
At line 1, insert x –;



Leave a Reply 15

Your email address will not be published. Required fields are marked *


mrtsilva

mrtsilva

Didn’t have success with any of the above answers.

Works changing the line 6 to
System.out.println(x–);

IO

IO

I guess tha there are a problem with the ocr and the answers that say
D.
At line 1, insert x –;

mean…
D.
At line 7, insert x –;

vlad

vlad

at line 7 insert: x–;

Kanke

Kanke

At line 7 insert x– ;

Is the only correct answer so I think that is what Option D is supposed to be. These are definitely fake dumps because the options are not even given correctly.

I doubt Oracle would make so many stupid mistakes in a single test 🙂

TC

TC

For option D, the line 7 should be insert x-;

Narayana Gowda

Narayana Gowda

Non of these. (answer is Replace line 6 with System.out.print (x–) 😉

Bruno

Bruno

That option is not up there. Option C is “Replace line 6 with System.out.println(-x)”,which prints 43210.
So the only option is D, assuming that it means, Insert x– at line 7;.

Belal

Belal

x-; isn’t even a statement. It should be at least x–; (two minus signs).

A lot of bad mistakes in this dump.

Belal

Belal

Ah, i see, there is bug in this webpage itself, it shosw two minus signs as a long dash. XD

omar

omar

none of the given options are correct;

A, B, and C lead to infinite loop. while D will generate compilation error.

the right answer is to replace line 6 with System.out.print(x–);

it seems that questions and answers are incorrect on this site!

Tomas

Tomas

Which modification enables the code to print 54321?

A. Replace line 12 With return (x > 0) ? false: true;
B. Replace line 6 with –x; and, at line 7, insert system, out. print (x);
C. Replace line 6 with System, out. print (–x) ;
D. At line 7, insert x –;

Answer: D

JoJo

JoJo

option D description is wrong,
it should be “At line 7, insert x–;”

Correct answer is D.

Birendra

Birendra

All the options mentioned is incorrect. changing line 6 to this System.out.print(x–); shall give the desired output “54321”

Simon

Simon

D.
I think the following is correct – instead of “At line 1 – use at line 7”
At line 1, insert x –;