btcq.net
当前位置:首页 >> 用循环从1加到100jAvA >>

用循环从1加到100jAvA

int i=1,sum=0; while(i sum+=i; i++; }

下面已经的答对了啊 int sum=0;//把1加100次 for (int i=1; i sum += 1; }//从1加到100 for (int k=1; k sum += k; }

public class test1{ public static void main(string args[]) { int a; for(int i=1;i<101;i++) a=a+1; system.out.println(a); } }

int i,sum=0; i=1; while(i{ sum+=i; i++; }

for (int i = 0; i < 10; i++) { for (int j = 1; j < 101; j++) { System.out.print(j+" "); } System.out.println(); }

第一次执行循环时;while (isum+=i; //i=0,sum=0 i++; //i=1 } 第二次:while (isum+=i; //i=1,sum=1 i++; //i=2 }其实你把循环里面的每条语句都在执行后用System.out.println输出你要看的变量的值不就OK了

import javax.swing.JOptionPane; public class Test { public static void main(String[] args) { for(int i=0;i<=100;i++){ if (i ==99){ JOptionPane.showMessageDialog(null, "循环到99","信息提示",JOptionPane.ERROR_MESSAGE); System.out.println("i="+i); } } } }

int sum = 0; int j = 0; while (j <= 100) { sum += j; j++; } System.out.println(sum); sum = 0; for (int i = 1; i <= 100; i++) { sum += i; } System.out.println(sum);

int count=0; for(int i=0;i<=100;++i) { count=count+i; System.out.println(count); }

int j=0; for(i=1;i

jingxinwu.net | wwfl.net | pznk.net | gyzld.cn | lyhk.net | 网站首页 | 网站地图
All rights reserved Powered by www.btcq.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com