What is the result?

Given the code fragment:
<code>
public class App {
public static void main (String [] args) {
path path = paths.get(C\\educations\\institute\\student\\report.txt);
system.out.printIn(getName(0): %s, path.getName(0));
system.out.prinIn(subpath(0, 2): %s path.subpath(0, 2));
}
}
</code>
What is the result?

Given the code fragment:
<code>
public class App {
public static void main (String [] args) {
path path = paths.get(C\\educations\\institute\\student\\report.txt);
system.out.printIn(getName(0): %s, path.getName(0));
system.out.prinIn(subpath(0, 2): %s path.subpath(0, 2));
}
}
</code>
What is the result?

A.
getName (0): C:\
subpath(0, 2): C:\education\report.txt

B.
getName (0): C:\
subpath(0, 2): education\institute

C.
getName(0): education
subpath(0, 2: education\institute\student

D.
getName(0): education
subpath(0, 2): education\institute

E.
getName(0): report.txt
subpath (0, 2): institute\student

Explanation:
The getName(int index) method returns a name element of this path as a Path object.
The subpath(int beginIndex, int endIndex) method returns a relative Path that is a subsequence of the name elements of this path.
Reference: java.nio.file.Path



Leave a Reply 1

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


Jan

Jan

Code doesn’t compile: println() change to >> printf()

public class App {
public static void main (String [] args){
Path path = Paths.get(“C:\\education\\institute\\student\\report.txt”);
System.out.printf(“get.Name(0): %s \n”, path.getName(0));
System.out.printf(“subpath(0, 2): %s”, path.subpath (0, 2));
}
}

D is correct