今天写了几个简单的java程序题http://blog.csdn.net/zs312979674/article/details/6830421求方法
解决方案 »
- 机器(web服务器)当掉前,在java程序里是如何判断
- 关于flex的初级问题
- 数据库查询月份的一个小问题
- 请问apache.jasper.JasperException错误如何修改
- 你的才能可以在这里体现,所有问题都可以在这里解决
- 哪里可以下载java的帮助文档
- applet显示图片的问题。(在html中不能引用策略文件(.policy)?)
- 有这个包吗?MyWindowLetter
- 很菜但很无赖!100分轻松获得
- 求救, 急啊, 请问如何设置在弹出一个Frame时把它设置成Modal形式, 谢谢!!!
- Jboss启动时提示错误,无法解析server目录下的文件
- 大侠们介绍一下java中的Class类,详细些
/*
*第一题
*/
public static int getDay(String strDate){
try {
int year = Integer.valueOf(strDate.substring(0,strDate.indexOf("年")));
int month = Integer.valueOf(strDate.substring(strDate.indexOf("年")+1,strDate.indexOf("月")));
int day = Integer.valueOf(strDate.substring(strDate.indexOf("月")+1,strDate.indexOf("日")));
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month-1);
c.set(Calendar.DAY_OF_MONTH, day);
return Calendar.get(Calendar.DAY_OF_YEAR);
} catch (Exception e) {
e.printStackTrace();
}
return -1;
}
/*
* 第二题
*/
public static void nine(){
for (int i=1; i<10; i++) {
for (int j=1; j<=i; j++) {
System.out.printf("%d*%d=%-2d ", j, i, j*i);
}
System.out.println();
}
}/*
* 第三题
*/
public static boolean testNumber(int num){
int sum=0, tmp=num, m=0;
while (tmp > 0) {
m = tmp%10;
sum += m*m;
tmp /= 10;
}
return sum == num;
}
int year = Integer.valueOf(strDate.substring(0, strDate.indexOf("年")));
int month = Integer.valueOf(strDate.substring(strDate.indexOf("年") + 1, strDate.indexOf("月")));
int day = Integer.valueOf(strDate.substring(strDate.indexOf("月") + 1, strDate.indexOf("日")));
Calendar calendar = new GregorianCalendar(year, month-1, day);
return calendar.get(Calendar.DAY_OF_YEAR);
}