Java output type question

Q.  Java: Predict the output:

int x = 786;
cout << setfill(‘*’) << setw(6) << x;

- Published on 29 Jun 15

a. 786***
b. **786
c. ***786
d. ******

ANSWER: ***786
 
When set() manipulator is used, then output is right justified. So Out of 6 width, 3 are used by variable x and remaining 3 width (Spaces) are filled with char * due to setfill().

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)