例3.4.
package bgio; public class cjava { public static void main(String[]args) { int i=1; int sum=0; while(i<=100) { sum=sum+i; i++; } System.out.println("sum"+sum); } }
例3.5
package bgio; public class cjava { public static void main(String[]args) { int i=1; int sum=0; do { sum=sum+i; i++; }while(i<=100); System.out.println("sum"+sum); } }
例3.6
package bgio; public class cjava { public static void main(String[]args) { int s=1; double n=1,t=1,pi=0; while((Math.abs(t))>(1e-7)) { pi=pi+t; n=n+2; s=-s; t=s/n; } pi=pi*4; System.out.println("pi="+pi); } }
2.数学方法不太知道.
3.明天继续写例题