This is a question I was asked today at a job interview:
Look at the following code:
int n=20;
for (int i =0; i<n; i--)
print("*");
You are allowed to change one and only one character in order for the loop to run exactly 20 times.
I wasn't able to answer the question at all. At first I thought to set i to 40, but then realized that 40 ins't smaller than 20.
My interviewer said that are 5 different answers for this question...
Please help me find the answers.
Change to
int n=20;
for (int i =0; i<n; n--)
print("*");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With