码迷,mamicode.com
首页 > 其他好文 > 详细

面试题目两题写法

时间:2019-01-12 21:42:30      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:stringbu   mave   process   name   folder   com   str   pytho   src   

第一题:

题目打印:
技术分享图片

java写法:

  public static void showTree(int level, File parentFolderPath) {
        if (parentFolderPath.isDirectory()) {
            File[] childFiles = parentFolderPath.listFiles();
            for (File file : childFiles) {
                showNameByLevel(level);
                System.out.println(file.getName());
                if (file.isDirectory()) {
                    showTree(level + 1, file);
                }
            }
        }
    }
    public static void showNameByLevel(int level) {
        StringBuffer stringBuffer = new StringBuffer();
        if (level > 0) {
            for (int i = 0; i < level; i++) {
                stringBuffer.append("\t");
            }
        }
        if(stringBuffer.length() >0) System.out.print("|" + stringBuffer);
        System.out.println("|");
        if (stringBuffer.length()>0) System.out.print("|" + stringBuffer);
        System.out.print("----");
    }
    @Test
    public void c23() {
        File file = new File("D:\\TOOL\\IDEASpace\\mavedome\\src\\test\\java");
//        printlen(file, 0);
        showTree(0, file);
    }

python写法:

第二提:

面试题目两题写法

标签:stringbu   mave   process   name   folder   com   str   pytho   src   

原文地址:http://blog.51cto.com/357712148/2342053

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!