计算8+88+888+…前10项之和

计算8+88+888+…前10项之和

编写应用程序,使用for循环语句计算8+88+888+…前10项之和。

	public class Demo09 {
		public static void main(String[] args) {
	      	// your code
	      long x=0,sum=0;
	      for(int i=0;i<10;i++){
	     	 x=x+(long)(8*(Math.pow(10,i)));
	        sum+=x;
	      }
	      System.out.println(sum);
	    }
	}

image-20220423163051205

posted @ 2022-04-23 16:38  涂勇军  阅读(447)  评论(0编辑  收藏  举报