What is the result?

Given the code fragment:
Path p1 = Paths.get(“/Pics/MyPic.jpeg”);
System.out.println (p1.getNameCount() +
“:” + p1.getName(1) +
“:” + p1.getFileName());
Assume that the Pics directory does NOT exist.
What is the result?

Given the code fragment:
Path p1 = Paths.get(“/Pics/MyPic.jpeg”);
System.out.println (p1.getNameCount() +
“:” + p1.getName(1) +
“:” + p1.getFileName());
Assume that the Pics directory does NOT exist.
What is the result?

A.
An exception is thrown at run time.

B.
2:MyPic.jpeg: MyPic.jpeg

C.
1:Pics:/Pics/ MyPic.jpeg

D.
2:Pics: MyPic.jpeg



Leave a Reply 7

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


CompileTester

CompileTester

B

smh

smh

why it prints count 2. please advise.

Berti John

Berti John

Because have Pics and MyPic.
if include other folder, e.g /Pics/Pics2/MyPic.jpeg

System.out.println (p1.getNameCount() +
“:” + p1.getName(1) +
“:” + p1.getFileName());

p1.getNameCount() = 3
p1.getName(1) Pics2
p1.getFileName() MyPic.jpeg

smh

smh

B.
2:MyPic.jpeg: MyPic.jpeg

Berti John

Berti John

B is correct