日期:2014-05-20  浏览次数:21955 次

面试题:大家都来解答吧
1、 字符串的最大长度
 2 简述单子模式在系统中的作用,并且举例说明
 3 简述Ajax的工作原理
 4 简述struts,hibernate,spring在系统中充当的角色
(二)分析题目:
 1、如下程序:public void isBoolean(String names[])(10)
{
for(String name:names)
{
System.out.println(name);
}
}
在weblogic8.0下执行错误。请问错在哪里。需要如何修改。

2 写一个程序统计C盘中各个类型文件的个数?



------解决方案--------------------
二,1)增强for循环是JDK5.0的新特征,改为普通for循环
------解决方案--------------------
2 写一个程序统计C盘中各个类型文件的个数?

Java code

public static void main(String[] args) throws Exception
    {
        Map<String,Integer> map = new HashMap<String,Integer>();
        searchFile(map,new File("e:"));
        
        Set set = map.entrySet();
        for(Iterator i = set.iterator();i.hasNext();)
        {
            Map.Entry<String, Integer> temp = (Map.Entry<String, Integer>)i.next();
            System.out.println(temp.getKey() + ":" + temp.getValue());
        }
    }
    public static void searchFile(Map map,File file) throws Exception
    {
        if(file.isFile())
        {
            if(file.getName().lastIndexOf(".") != -1)
            {
                String fileName = file.getName().toLowerCase();
                String suffix = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
                if(map.containsKey(suffix))
                {
                    map.put(suffix, Integer.parseInt(map.get(suffix).toString()) + 1);
                }
                else
                {
                    map.put(suffix, 1);
                }
            }
            
        }
        else
        {
            File[] files = file.listFiles();
            for(File tempFile:files)
            {
                searchFile(map,tempFile);
            }
        }
    }