您的位置:首页 > 其它

玩codehunter level02

2015-07-10 11:56 302 查看
public class Program {

    public static int[] Puzzle(int n) {

        int[] test = new int
;

        for(int i=0; i<n; i++)

             test[i]=i;

        return test;

    }
}

================================================

public class Program {

    public static int[] Puzzle(int n) {

        int[] test = new int
;

        for(int i=0; i<n; i++)

            test[i] = i*n;

        return test;

    }

}

================================================

public class Program {

    public static int[] Puzzle(int n) {

         int[] test = new int
;

         for(int i=0; i<n; i++)

             test[i] = i*i;

             

         return test;

    }

}

===============================================

public class Program {

    public static int Puzzle(int[] v) {

            int sum = 0;

            for(int i=0;i < v.length; i++)

                sum += v[i];

                

            return sum;

 

    }

}

================================================

public class Program {

    public static int Puzzle(int n) {

        int sum=0;

        for(int i=0; i< n; i++)

            sum += i*i; 

        return sum;    

    }

}

(系统显示还可以优化)

用平方和公式

===============================================

Rating 1:

public class Program {

    public static int Puzzle(String s) {

        int count =0;

        for(int i=0;i<s.length();i++)

            if(s.charAt(i)=='a')

              count++;

        return count; 

    }

}

有待优化

===============================================

Rating 2:

public class Program {

    public static int Puzzle(String s, char x) {

        int count=0;

        for(int i=0; i<s.length();i++)

           if(s.charAt(i)==x)

             count++;

             

        return count;     

    }

}

有待优化

================================================
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: