有次参加一个公司的笔试,然后有道题是让你写出能体现出自己当前水平的代码。我觉得这道题挺开放的,知道CSDN上牛人比较多,大家各抒己见,都各自写段代码出来让大家开开眼界咯!
解决方案 »
- 【送分】一个多态的例子需要讲解
- Java反射NoSuchMethodException问题
- 各位大哥大,帮忙找找程序错误
- 主线程创建了子线程,如何让主线程退出,而子线程仍然运行?
- 大家帮帮忙,小弟刚学java不久有个问题?
- 请教个图形的算法??
- 问:在Applet中,绘制出的图形如何让用户能够把它复制到Word中!
- 在线等待!!JBiulder 7 如何注册?急啊
- 关于apache,resin.tomcat,iis等服务软件的端口问题?
- IO流中使用BufferedWriter复制文件关于换行的问题
- 联通短信网关回复消息问题
- 通过一个按钮响应添加另一个组件,,需要放大或者拉动窗口组件在会出现??
* 方法解析添加了注解的类,并将类的一些信息(如 作用域,配置名称)添加并返回。
* @param packagePath 该类的全路径(包括包名)
* @return 如果该类上有SpringBeanClass的注解,那么给这个类赋值并返回类的实例,如果该类没有添加注解,则返回null
*/
private ClassBean getClassBeanInfo(String packagePath){
ClassBean cb = null;
String path = packagePath.substring(0, packagePath.lastIndexOf(".class"));
Class<?> bean = null;
try {
bean = Class.forName(path);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
SpringBeanClass classBean = bean.getAnnotation(SpringBeanClass.class); // 获取该类上面的注解类实例
if(classBean != null){
cb = new ClassBean();
/**为scope设置值,默认为single模式的---------begin*/
String scope = classBean.scope();
if(scope == null || scope.equals("")){ // 如果scope没有设置值,即为默认值时,scope设置为single模式的
scope = "single";
}
/**为scope设置值,默认为single模式的---------end*/
/**为xmlName设置值,默认为该类的类名首字母小写---------begin*/
String xmlName = classBean.name();
if(xmlName == null || xmlName.equals("")){ // 如果scope没有设置值,即为默认值时,scope设置为single模式的
xmlName = SpringUtil.firstWordLowerCase(SpringUtil.spiltClassName(path)); //默认为该类的类名首字母小写
}
/**为xmlName设置值,默认为该类的类名首字母小写---------end*/
cb.setPath(path);
cb.setScope(scope);
cb.setXmlName(xmlName);
}
return cb;
}
for(int i=0;i<=3*(5+1);i++) System.out.print((char)(i%(5+1)==0?13:42));
如果是,举例你看到过或写过的你个人觉得比较好的代码(包括代码组织,设计思想,逻辑思维,算法等),还说的过去
所以对于这样的考题,是我的话我就如此回答
public class SimpleIsBest {
public static void main(String[] args) {
System.out.printf("这道考题太失败,太有水平的代码你看不懂,还是你直接评价吧: %s\n", (args.length==0 ? "不评价" : args[0]));
}
}
public String[] contents = new String[10];
public synchronized void put(String content){
/**
* 这里用while而不是用if,放置线程假醒的情况!
*/
while(contents.length == 10){
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}那段while用得感觉挺好!