日期:2014-05-20  浏览次数:20806 次

java程序题
今天写了几个简单的java程序题

http://blog.csdn.net/zs312979674/article/details/6830421

求方法

------解决方案--------------------
for example
Java code
/* 
*第一题  
*/  
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;
}

------解决方案--------------------
第一题:
Java code

                public static int getDay0(String strDate){
        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);
    }

------解决方案--------------------
探讨

for example
Java code
/*
*第一题
*/
public static int getDay(String strDate){
try {
int year = Integer.valueOf(strDate.substring(0,strDate.indexOf("年")));
int month = Intege……

------解决方案--------------------
学习中、、、、、