rjps.net
当前位置:首页 >> jAvA实现求1到100的和 >>

jAvA实现求1到100的和

int sum = 0; for(int i=1;i<100;i++){ sum+=i; } 就这么简单

class Sum+12345 { public static void Main() { int sum=0; for ( int i = 0 ; i sum = sum + i; Console.WriteLine(sum); } }

public class $ { public static void main(String[] args) { int sum = 0; for (int i = 1; i sum += i; } System.out.println("和是:" + sum); try { System.out.println(sum / 0); } catch (Exception e) { e.printStackTrace(); } try { System.out.println(sum / 5); } catch (Exception e) { e.printStackTrace(); } } }

public static void main(String args[]){ int sum=0; for(int i=1;i<=100;i++){ sum+=i; } System.out.println(sum); }

class demo { public static void main(string[] args) { int x=0; for(int y=1;y { x=x+y; } system.out.println(x); } }

int total=0; for(int i=1;i total+=i; } System.out.println("1到100的和为:"+total);

public class A //阶乘1到10方法; { // public static void main(String[]args) { int i=1,n=1,sum=1; while (n<=100) { sum=sum*i; System.out.println(sum); i++; n++; } } } 阶乘从1到10;

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

for(int i=1;i<=100;i++){ sum+=i; }

class Test{ public static void main(String[] args){ int dan=0,shuang=0; for(int i=1; i<=100; i++){ if( i%2==0 ){ shuang += i; }else{ dan += i; } } System.out.println("单数之和:"+dan); System.out.println("双数之和:"+shuang); } }

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