課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)升級版
如何用for累計疊加
2019-12-26
源自:Java入門第一季(IDEA工具)升級版 4-9
正在回答
//用while 輸出
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? int sum=0;
? ? ? ? int i=1;
? ? ? ? int n=10;
? ? ? ? while (i< n){
? ? ? ? ? ? sum=sum+i;
? ? ? ? ? ? i++;
? ? ? ? }
? ? ? ? System.out.println("和為:"+ sum);
}
舉報
0基礎萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎語法開始
1 回答輸入2個正整數m和n,求其最大公約數。
4 回答用循環(huán)語句while輸出1到5的數字,
1 回答大神幫忙解答一下啊1+1/(1+2)+1/(1+2+3)+1/(1+2+3+4)+....+1/(1+2+3+4+...+n)
1 回答計算并輸出n的階乘 (設n=10)
1 回答如果是用戶輸入一個分數,要求輸出加分前后成績和加分次數呢??
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優(yōu)惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2019-12-26
//用while 輸出
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? int sum=0;
? ? ? ? int i=1;
? ? ? ? int n=10;
? ? ? ? while (i< n){
? ? ? ? ? ? sum=sum+i;
? ? ? ? ? ? i++;
? ? ? ? }
? ? ? ? System.out.println("和為:"+ sum);
}
}