IBM实习生笔试题目(6)
来源:互联网 发布:艺术字设计软件下载 编辑:程序博客网 时间:2024/04/30 13:52
题目:
写程序
(1)用java语言写一个程序,删除一个目录。
(2)用java语言写一个程序,读取一个properties文件。
(3)写一个Singleton。
(4)用java语言实现插入排序。
import java.io.File;public class Delete { public static void deleteFile(File file){ if(file.isFile()){ file.delete(); }else{ File fileArray[] = file.listFiles(); for(int i = 0; i < fileArray.length; i++){ fileArray[i].delete(); } } if(file.exists()){ file.delete(); } } public static void main(String[] args){ File file = new File("e:"+File.separator+"test"); deleteFile(file); }}
import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.util.Properties;public class ReadPro { public static void main(String[] args){ Properties prop = new Properties(); try {prop.load(new FileInputStream(new File("e:"+File.separator+"java.properties")));} catch (IOException e) {e.printStackTrace();} System.out.println(prop.getProperty("name")); System.out.println(prop.getProperty("age")); System.out.println(prop.getProperty("school")); }}
或者:
import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.Scanner;public class ReadPro { public static void main(String[] args){ File file = new File("e:"+File.separator+"java.properties"); FileInputStream file_in = null;try {file_in = new FileInputStream(file);} catch (FileNotFoundException e) {e.printStackTrace();} Scanner sc = new Scanner(file_in); while(sc.hasNextLine()){ String line = sc.nextLine(); int index = line.indexOf('='); System.out.print(line.substring(0,index)+"的属性值为");//注意取到的是index-1的位置。 System.out.println(line.substring(index+1,line.length())); } }}
class Singleton { private static Singleton s; private Singleton(){ System.out.println("A Singleton Model example"); } public static Singleton getSingleton() { if(s==null)s=new Singleton(); return s; }}
构造方法私有化了。只能通过方法getSingleton获得实例,且该实例为静态的成员变量,所以一个类只有一个实例。
4)略。
- IBM实习生笔试题目(6)
- IBM实习生笔试题目
- IBM实习生笔试题目(1)
- IBM实习生笔试题目(2)
- IBM实习生笔试题目(3)
- IBM实习生笔试题目(4)
- IBM实习生笔试题目(5)
- IBM实习生笔试题
- 2011微软中国实习生笔试题目
- 2011淘宝实习生笔试题目
- 2011Oracle实习生笔试题目
- 2011腾讯实习生笔试题目
- 微软实习生招聘笔试题目
- 微软2013实习生笔试题目
- 2011阿里巴巴实习生笔试题目
- 2014阿里巴巴实习生笔试题目
- 阿里实习生招聘笔试题目
- 2014阿里巴巴实习生笔试题目 .
- Oracle 10g数据库迁移的经验 Windows环境
- 真机调试Error launching remote program: failed to get the task for process xxx.
- 利用VTS与bacnet协议栈进行通信---ReadProperty
- windows-IOCP模型总结
- hdu 1059 优先级队列
- IBM实习生笔试题目(6)
- fiddler替换服务器上文件进行本地调试
- 透彻理解异常并合理使用异常
- liux文件的每行末尾^M$ 和$
- H264 video RTP payload and SDP
- C++ 虚函数表解析
- 进程与线程区别
- HBase性能优化方法总结(一):表的设计
- SSDT Hook的妙用-对抗ring0 inline hook