首页 > 技术文章 > 计算8+88+888+…前10项之和

tuyongjun 2022-04-23 16:38 原文

计算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

推荐阅读