2013/05/29面试
来源:互联网 发布:vb 串口扫描枪 编辑:程序博客网 时间:2024/05/17 19:21
三个编程题:1.String的map转成二维数组。2.Integer的List排序。3.某个目录下文件类型总数。
1.
import java.util.Iterator;import java.util.LinkedHashMap;import java.util.Map;import java.util.Set;public class Map2Array {public static void main(String[] args) {//Map m =new HashMap(); //显示的是3,2,1 Map<String,String> m =new LinkedHashMap<String, String>(); //显示的是1,2,3 m.put("1","aaaa"); m.put("2","baaa"); m.put("3","caaa"); String[][] s = map2Array(m); if(s!=null) for(String [] ss:s){ for(String sss:ss){ System.out.print(sss+" "); } System.out.println(); } }static String[][] map2Array(Map map) {int length = map==null?0:map.size();if(length==0){return null;}String[][] result= new String[length][2];Set set = map.keySet();Iterator iterator = set.iterator();int i=0;while(iterator.hasNext()) {String key = (String) iterator.next();result[i][0]=key;result[i++][1] = (String) map.get(key);}return result;}}
2
import java.util.ArrayList;import java.util.Collections;import java.util.List;public class ListSort {public static void main(String[] args) {List<Integer> oldList = new ArrayList<Integer>();oldList.add(1);oldList.add(5);oldList.add(8);oldList.add(2);System.out.println("开始: ");for(int i:oldList) {System.out.print(i+"-");}Collections.sort(oldList);System.out.println("\n升序: ");for(int i:oldList) {System.out.print(i+"-");}Collections.reverse(oldList);System.out.println("\n降序:");for(int i:oldList) {System.out.print(i+"-");}System.out.println("\n最大:");System.out.print(Collections.max(oldList));System.out.println("\n最小:");System.out.print(Collections.min(oldList));}}
3.
import java.io.File;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;public class CountKindsFile {/** * @param args */public static void main(String[] args) {String filePath = "F:\\Test";String fileType = "";File rootDirectory = new File(filePath);File[] files = rootDirectory.listFiles();System.out.println("总共有 "+files.length+" 个文件.");Map<String,Integer> m = new HashMap<String, Integer>();for(File f:files){if(f.isDirectory()) {if(m.containsKey("folder")) {m.put("folder", m.get("folder")+1);} else {m.put("folder", 1);}} else {fileType = f.getName().substring(f.getName().lastIndexOf(".")+1);if(m.containsKey(fileType)) {m.put(fileType, m.get(fileType)+1);} else {m.put(fileType, 1);}}}System.out.println("总共有 "+m.size()+" 种文件.");Set set = m.keySet();Iterator iterator = set.iterator();while(iterator.hasNext()) {String key = (String) iterator.next();Integer value = m.get(key);System.out.println(key+"有"+value+"个");}}}
结果:
分割————————————————————————————————————————————————————————————————————
两个数据库题:
1.表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选C.
2.查询出每门课都大于80分的学生姓名
score表
name subject score
张三 语文 81
张三 数学 75
李四 语文 76 特意改为85
李四 数学 90
王五 语文 81
王五 数学 100
王五 英语 90
1.
select case when A>B then case when A>C then A else C end else case when B>C then B else C end end as name from member详细看 猛击
2.在网上查询大量资料后,看到的情况都是李四的语文为76,特意改为85,按照网上的解决方案为:
select distinct name from score where name not in(select distinct name from score where score<80)
得到的结果为:李四和王五。
从题目中得知张三和李四是没有英语成绩,再怎么也不会出现在最后的结果里。
故我所写的有点繁琐:
select namefrom(select name,max(case subject when '语文' then score end) as yuwen,max(case subject when '数学' then score end) as shuxue,max(case subject when '英语' then score end) as enfrom scoregroup by name) tempwhere yuwen>80 and shuxue>80 and en>80;若有好的SQL尽情贴上。
- 2013/05/29面试
- 360 2013-10-29面试
- 【笔试or面试】腾讯2013实习生面试
- 面试感触【2014.3.29】
- 面试2014-10-29
- JAVA面试 05
- 05-面试总结
- 2014.09.05面试总结
- 面试2016/01/05
- 2013年面试总结
- 2013CVT实习面试
- 2013华为实习面试
- 2013/06/14面试
- 2013年华为面试
- 面试经历--2013
- java面试宝典2013
- 2013有道面试
- 2013-12-21面试
- 在Tomcat上使用日志分析工具Awstats
- 常用电平标准(TTL、CMOS、LVTTL、LVCMOS、ECL、PECL、LVPECL、RS232)
- JAVA AES加密 对应的 C# 方法
- 中国各省市编号(具体到二级市、区、县)
- iphone中GPS精确定位及反向获取地址信息
- 2013/05/29面试
- highcharts图表 line_basic封装
- 20年嵌入式领域开发经验精华
- 程序员40岁之后怎么办
- LSI SAS 1068E Raid CentOS 5.5 安装实例浪潮NF5220系列
- Shell 编程基础
- 操作系统_再识(Linux设备文件简介)
- apktool + smali + dex2jar + jdgui实现apk反编译
- 操作系统_再识(Linux Platform Device and Driver)