求1+2+3+…+n
題目描述:
求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等關鍵字及條件判斷語句(A?B:C)。
Code:
public class Solution {
public int Sum_Solution(int n) {
return (n+(int)Math.pow(n,2))>>1;
}
}
喜歡折騰代碼的加羣(羣號:822286811)一起交流學習【Java、python、VBA、Shell、Linux、dos、數據分析、拆機、裝系統技術交流羣】
點擊鏈接加入羣聊【計算機技術交流】