你是出学Java吧!怎么能偷懒呢?

解决方案 »

  1.   

    大概是JAVA有无数的库可以使用,所以最容易偷懒吧... :)1. 用循环嵌套,穷举 千和百位的数字2. 注意大月 和 小月,及2月份的特殊性3. 利用公式 c^2 = a^2 + b^2 及 maxc = a+b+c: 已知a的长度,用循环穷举符合上述两方程的b,c的值。4. 
    long fibonacci(long n)
    {
      if (n == 1)
        return 1;
      else (n == 2)
        return 2;
      else
        return fibonacci(n-1) + fibonacci(n-2);
    }5. 是背包问题,是属于NP难的,可以利用回朔算法。可以GOOGLE,有无数的代码...
      

  2.   

    呵呵  真的不好意思学,两年了都这样的水平。 这两天忙帮MM整理宿舍真的没时间做。
    希望有人给帮我写写代码。循环最好用叠代。不要用 for.... 这样的。  十分感谢
      

  3.   

    这是第二题.刚好写了一个
    使用的Date类.现在这个是不被推荐使用的类.
    不过功能还是完成了.想改就自己改吧.import java.util.*;/*
     * Created on 2004-8-12
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     *//**
     * @author FreeKnight
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    public class MyDay {
    public static void main(String[] args) {

    int total = 0;
    Date beday = new Date(2001,10,7);//开始的日期
    Date today = new Date();//当前日期,你可以自己把它改为需要的日期
    today.setYear(today.getYear()+1900);//如果你使用的是自定义的当前日期.这行可以注释掉
    int[] nomalday = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    int[] ennomalday = {0,31,29,31,30,31,30,31,31,30,31,30,31};

    //取得开始年份当月所过的天数,
    if (beday.getYear() % 4 == 0 && beday.getYear() % 400 != 0)
    {
    total += ennomalday[beday.getMonth()] - beday.getDate();
    }
    else 
    total += nomalday[beday.getMonth()] - beday.getDate();
    //取得当前年份的月份所过的天数
    total += today.getDate(); //取得开始年份所过月份的天数
    for (int i = beday.getMonth()+1 ; i<= 12; i++)
    {
    if(today.getYear() % 4 == 0 && today.getYear() % 400 !=0)
    {
    total += ennomalday[i];
    }
    else
    {
    total += nomalday[i];
    }
    }
    //取得当前年份所过月份的天数
    for (int i = 1; i <  beday.getMonth() ; i++)
    {
    if(today.getYear() % 4 == 0 && today.getYear() % 400 !=0)
    {
    total += ennomalday[i];
    }
    else
    {
    total += nomalday[i];
    }
    }

    // 取得所差整年的天数
    for (int i = beday.getYear() + 1; i < today.getYear(); i++)
    {
    if(i % 4 == 0 && i % 400 !=0)
    {
    total += ennomalday[beday.getMonth()];
    total += 366;
    }
    else
    {
    total += nomalday[beday.getMonth()];
    total += 365;
    }
    }

    System.out.println("两年相差的天数 :" + total);
    }
    }
      

  4.   

    试题1
    for(int i = 10000/57 ; i < 10000/57 ; i++)
    {
       result = i*57;
       //比较以下是否在你要的数据中,用字符串比较
    }
    for(int i = 10000/67 ; i < 10000/67 ; i++)
    {
       result = i*67;
    //比较以下是否在你要的数据中,用字符串比较
    }
    这样就不用穷举了
    试题2
    可以通过一的参数
    获得long型的time,为t1
    通过给出的参数二获得long型time,为t2
    (t2-t1)/(24*3600*1000)
    这样就得到天了