exam questions

Exam 1z0-829 All Questions

View all questions & answers for the 1z0-829 exam

Exam 1z0-829 topic 1 question 17 discussion

Actual exam question from Oracle's 1z0-829
Question #: 17
Topic #: 1
[All 1z0-829 Questions]

Given the content of the in.txt file:
0123456789
and the code fragment:

What is the content of the out.txt file?

  • A. 012345678
  • B. 01234567801234
  • C. 01234567
  • D. 0123456789
  • E. 012345678901234
  • F. 0123456789234567
Show Suggested Answer Hide Answer
Suggested Answer: F 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
xplorerpj
7 months, 2 weeks ago
Correct answer is F
upvoted 1 times
...
xplorerpj
7 months, 3 weeks ago
Buffer only contains [0, 1, 2, 3, 4, 5, 6, 7] In second iteration, in.read(buffer) becomes "-1" . How is the answer F "0123456789234567" ? I ran the program & see only 01234567 in output file.
upvoted 1 times
...
j_jain
11 months, 1 week ago
Correct answer is F Buffer already contains 01234567 and we have 89 left so next time it will replace 0 with 8 and 1 with 9. As there is no data left so it will write 89234567.
upvoted 2 times
...
james2033
11 months, 3 weeks ago
Selected Answer: F
package q17; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Q17 { public static void main(String[] args) throws Exception { char[] buffer = new char[8]; int count = 0; try (FileReader in = new FileReader("D:\\in.txt"); FileWriter out = new FileWriter("D:\\out.txt")) { while ((count = in.read(buffer)) != -1) { out.write(buffer); } } // catch (FileNotFoundException e) { // throw new RuntimeException(e); // } catch (IOException e) { // throw new RuntimeException(e); // } } } // Result: // 0123456789234567
upvoted 3 times
...
supersquax
1 year ago
Correct option is F, because the buffer is of size 8. Therefore, it can only read 8 characters at a time. First 8 digits in F are correct and the entire thing is of length 16. Although the first 8 digits in B and E are correct, the entire length doesn't add it. Doesn't make sense that the buffer first reads 8 chars, then 6 more in B or 7 more in E.
upvoted 1 times
...
omegavalou
1 year ago
why is the right option F?
upvoted 2 times
4d8d7fe
6 months, 3 weeks ago
In the first iteration de char array is 01234567(only can contain 8 size). But in the second iteration is 89234567
upvoted 2 times
...
...
meltedolive
1 year ago
right option is F
upvoted 1 times
...
Tojose
1 year ago
the right option is F. 0123456789234567
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago