Menu
Question Index
...

What will be the output of the following program? The directory structure is given below.

import java.io.File;
public class PrintDirectories {
    public static void main(String[] args) {
        File file = new File("E:\\meritcampus\\");
        printDirectories(file, 0);
    }
    public static void printDirectories(File parent, int level) {
        for (File file : parent.listFiles()) {
            System.out.print(file.getName() + "~" + level + " ");
            printDirectories(file, level++);
        }
    }
}
Directories


cam~0 camp~1 campu~2 campus~3 campusA~4 campusB~5 campusC~6 mer~1 meri~2 merit~3
cam~0 camp~0 campu~0 campus~0 campusA~0 campusB~1 campusC~2 mer~1 meri~1 merit~2
cam~0 camp~1 campu~1 campus~1 campusA~1 campusB~2 campusC~3 mer~1 meri~1 merit~2
cam~0 camp~0 campu~0 campus~0 campusA~0 campusB~0 campusC~0 mer~0 meri~0 merit~0
Compilation Error
Runtime Error

Doubts

Problems

Topic: Unknown

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App