本帖最后由 My_work 于 2014-3-3 19:57 编辑
- public static int getResult(int num1, int num2)
- {
-
- int result = 0;
- for(int i = 0; i < num2 ; i++)
- {
- result += num1;
- }
-
- return result;
- }
-
复制代码 与-
- public static int getResult_2(int num1, int num2)
- {
- int times = 0;
- int result2 = 0;
- while(num2 != 1)
- {
- num2 = num2 >> 1;
- times++;
- }
- result2 = num1 << times;
- return result2;
- }
复制代码 的效率哪个要高一些??
|
|