ImageVerifierCode 换一换
格式:DOCX , 页数:22 ,大小:21.63KB ,
资源ID:11208795      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-11208795.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(黑马入学测试面试题答案整理解析.docx)为本站会员(b****3)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

黑马入学测试面试题答案整理解析.docx

1、黑马入学测试面试题答案整理解析1.定义一个交通灯枚举,包含红灯、绿灯、黄灯,需要有获得下一个灯的方法;例如:红灯获取下一个灯是绿灯,绿灯获取下一个灯是黄灯。public enum Lamp RED(GREEN),GREEN(YELLOW),YELLOW(RED); private String next; private Lamp(String next) this.next = next; public Lamp nextLamp() return Lamp.valueOf(next); 2、 写一个ArrayList类的代理,实现和ArrayList中完全相同的功能,并可以计算每个方法运行

2、的时间。public class test1 public static void main(String args) final ArrayList target = new ArrayList(); List proxy = (List)Proxy.newProxyInstance( List.class.getClassLoader(), ArrayList.class.getInterfaces(), new InvocationHandler() Override public Object invoke(Object proxy, Method method, Object arg

3、s) throws Throwable long beginTime = System.currentTimeMillis(); Thread.sleep(10); Object reVal = method.invoke(target, args); long endTime = System.currentTimeMillis(); System.out.println(method.getName()+ runing time is +(endTime-beginTime); return reVal; ); proxy.add(nihaoa); proxy.add(nihaoa); p

4、roxy.add(nihaoa); proxy.remove(nihaoa); System.out.println(proxy.toString(); 3. ArrayList list = new ArrayList();在这个泛型为Integer的ArrayList中存放一个String类型的对象。public class test2 public static void main(String args) throws Exception ArrayList list = new ArrayList(); Method method = list.getClass().getMetho

5、d(add, Object.class); method.invoke(list, i am a String); System.out.println(list.toString(); 4、 一个ArrayList对象aList中存有若干个字符串元素, 现欲遍历该ArrayList对象, 删除其中所有值为abc的字符串元素, 请用代码实现。public class test4 public static void main(String args) ArrayList aList = new ArrayList(); aList.add(abc); aList.add(nihaoa); aL

6、ist.add(nihaoa); aList.add(abc); aList.add(cdb); aList.add(abc); aList.add(cdb); System.out.println(aList.toString(); Iterator it = aList.iterator(); while(it.hasNext() String str = it.next(); if(str.equals(abc) it.remove(); System.out.println(aList.toString(); 5、 编写一个类,增加一个实例方法用于打印一条字符串。 并使用反射手段创建该

7、类的对象, 并调用该对象中的方法。public class test5 public static void main(String args)throws Exception Class clazz = myClass.class; Method method = clazz.getMethod(printStr, String.class); method.invoke(clazz.newInstance(), ni hao ma? this my print str); class myClass public void printStr(String str) System.out.p

8、rintln(str); 6 、 存在一个JavaBean,它包含以下几种可能的属性: 1:boolean/Boolean 2:int/Integer 3:String4:double/Double 属性名未知,现在要给这些属性设置默认值,以下是要求的默认值: String类型的默认值为 字符串 int/Integer类型的默认值为100 boolean/Boolean类型的默认值为truedouble/Double的默认值为0.01D.只需要设置带有getXxx/isXxx/setXxx方法的属性,非JavaBean属性不设置,请用代码实现public class test7 public

9、static void main(String args) throws Exception Class clazz = Class.forName(cn.heima.test.testBean); Object bean = clazz.newInstance(); BeanInfo beanInfo = Introspector.getBeanInfo(clazz); / System.out.println(beanInfo); PropertyDescriptor propertyDescriptors = beanInfo .getPropertyDescriptors(); for

10、 (PropertyDescriptor pd : propertyDescriptors) / System.out.println(pd); / 获取属性名 Object name = pd.getName(); / 获取属性类型 Object type = pd.getPropertyType(); / 获取get方法 Method getMethod = pd.getReadMethod(); / 获取set方法 Method setMethod = pd.getWriteMethod(); if (!class.equals(name) if (setMethod != null)

11、if (type = boolean.class | type = Boolean.class) setMethod.invoke(bean, true); if (type = String.class) setMethod.invoke(bean, ); if (type = int.class | type = Integer.class) setMethod.invoke(bean, 100); if (type = double.class | type = Double.class) setMethod.invoke(bean, 0.01D); if (getMethod != n

12、ull) System.out.println(type + + name + = + getMethod.invoke(bean, null); class testBean private boolean b; private Integer i; private String str; private Double d; public Boolean getB() return b; public void setB(Boolean b) this.b = b; public Integer getI() return i; public void setI(Integer i) thi

13、s.i = i; public String getStr() return str; public void setStr(String str) this.str = str; public Double getD() return d; public void setD(Double d) this.d = d; 7、 定义一个文件输入流,调用read(byte b) 方法将exercise.txt文件中的所有内容打印出来(byte数组的大小限制为5,不考虑中文编码问题)。public class test8 public static void main(String args) Fi

14、leInputStream fr = null; try fr = new FileInputStream(d:/exercise.txt); byte bt = new byte5; int len = 0; while(len = fr.read(bt)!=-1) for (int i = 0; i len; i+) System.out.print(char)bti); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); finally if(fr!=null) try fr.close

15、(); catch (IOException e) e.printStackTrace(); finally fr = null; 8、 编写一个程序,它先将键盘上输入的一个字符串转换成十进制整数,然后打印出这个十进制整数对应的二进制形式。 这个程序要考虑输入的字符串不能转换成一个十进制整数的情况,并对转换失败的原因要区分出是数字太大,还是其中包含有非数字字符的情况。提示:十进制数转二进制数的方式是用这个数除以2,余数就是二进制数的最低位,接着再用得到的商作为被除数去除以2,这次得到的余数就是次低位,如此循环,直到被除数为0为止。其实,只要明白了打印出一个十进制数的每一位的方式(不断除以10,

16、得到的余数就分别是个位,十位,百位),就很容易理解十进制数转二进制数的这种方式。public class test9 public static void main(String args) Scanner sc = null; while (true) sc = new Scanner(System.in); String str = sc.nextLine(); int a = 0; if (isOctNumers(str) a = Integer.valueOf(str); else System.out.println(输入不正确,请重新输入); continue; System.ou

17、t.println(toBinary(a); sc.close(); private static boolean isOctNumers(String str) try Integer.parseInt(str); return true; catch (NumberFormatException e) return false; public static String toBinary(Integer decimal) StringBuilder sb = new StringBuilder(); int x = 0; while (decimal != 0) x = decimal %

18、 2; decimal = (int) (decimal / 2); sb.append(x); sb.reverse(); return sb.toString(); 9、 金额转换,阿拉伯数字转换成中国传统形式。 例如:101000001010 转换为 壹仟零壹拾亿零壹仟零壹拾圆整public class testt10 private static final char data = 零, 壹, 贰, 叄, 肆, 伍, 陆, 柒, 捌, 玖 ; private static final char units = 圆, 拾, 佰, 仟, 万, 拾, 佰, 仟, 亿, 拾, 佰, 仟 ; S

19、uppressWarnings(resource) public static void main(String args) while (true) Scanner sc = new Scanner(System.in); long l = sc.nextLong(); System.out.println(convert(l); public static String convert(long money) StringBuffer sbf = new StringBuffer(); int uint = 0; while (money != 0) sbf.insert(0, units

20、uint+); sbf.insert(0, data(int) (money % 10); money = money / 10; / 去零 return sbf.toString().replaceAll(零仟佰拾, 零).replaceAll(零+万, 万) .replaceAll(零+亿, 亿).replaceAll(亿万, 亿零) .replaceAll(零+, 零).replaceAll(零圆, 圆); 10.取出一个字符串中字母出现的次数。如:字符串:abcde%kka27qoq ,输出格式为:a(2)b(1)k(2).public class test1 public stati

21、c void main(String args) String str = abcdekka27qoA*&AAAq; CountChar(str); private static void CountChar(String str) char c = str.toCharArray(); System.out.println(c); Map map = new LinkedHashMap(); for (int i = 0; i c.length; i+) if (ci = 65)|(ci=97&ci=112) if (!(map.keySet().contains(ci) map.put(c

22、i, 1); else map.put(ci, map.get(ci) + 1); StringBuilder sb = new StringBuilder(); IteratorMap.Entry it = map.entrySet().iterator(); while (it.hasNext() Map.Entry entry = it.next(); sb.append(entry.getKey() + ( + entry.getValue() + ); System.out.println(sb); /* *11、 将字符串中进行反转。abcde - edcba */public c

23、lass test5 public static void main(String args) String str = abcdgrdfgse; System.out.println(reverse(str); private static String reverse(String str) String result = ; char c = str.toCharArray(); for (int i = c.length-1; i = 0 ; i-) result += ci; return result; /* * 12、 * 已知文件a.txt文件中的内容为“bcdeadferwp

24、lkou”,请编写程序读取该文件内容,并按照自然顺序排序后输出到b.txt文件中。即b * .txt中的文件内容应为“abcd.”这样的顺序。 */public class test6 public static void main(String args) FileInputStream fis = null; FileOutputStream fos = null; try fis = new FileInputStream(D:/a.txt); fos = new FileOutputStream(D:/b.txt); byte c = new bytefis.available();

25、while (fis.read(c) != -1) Arrays.sort(c); fos.write(c); fos.flush(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); finally try fis.close(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); try fos.close(); catch (IOException e) / TODO Auto-g

26、enerated catch block e.printStackTrace(); /* * 13、 编写一个程序,获取10个1至20的随机数,要求随机数不能重复。 */public class test7 public static void main(String args) System.out.println(getRandom(); public static List getRandom() Random rd = new Random(); ArrayList al = new ArrayList(); int i = 0; while(i!=10) int r = rd.nextInt(20); if(!al.contains(rd) al.add(r); i+; return al; /* * 14、 编写三各类Ticket、SealWindow、TicketSealCenter分别代表票信息、售票窗口、售票中心。售票中心分配一定数量的票, * 由若干个售票窗口进行出售,利用你

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2