zoukankan      html  css  js  c++  java
  • Java小程序3(2015-8-10)

    使用while单循环求1!+2!+3!+...+6!+7!

    1、

    public class Test33{  public static void main(String[]args){  

            int i=1;

            int j=1;  

            int sum=0;

            while (i<=7)         {     

                                    j=j*i;                

                                    i++;   

                                 sum=sum+j;//1*1+1*1*2+1*1*2*3....

             }  System.out.println(sum);  } }

    2、

    public class Test3{

                 public static void main(String[] args){        

                               int i = 1;  

                               int j = 1;  

                               int sum = 0;   

                                        //--每个数阶乘的和  

                              int jc = 1;

                     /*   sum = 1*1+1*2+1*2*3+1*2*3*4......   */

                  while(i<=7){       

                                     //--单独的每个数的阶乘和    

                                while(j<=i){         

                                           jc = jc*j;    

                                                j++;    

                                }    

                                i++;       

                                  sum = sum + jc;    

      }   System.out.println("sum:"+sum);

     } }

  • 相关阅读:
    html component(htc)入门(转)
    eclipse maven plugin 插件 安装 和 配置
    Error configuring application listener of class org.springframework.web.util.IntrospectorCleanupListener
    局域网下tomcat部署的服务让别人也能访问
    基于geowebcache切片服务的发布
    vee-validate-----专门用来做表单验证的vue插件
    移动端触摸事件
    使用svg显示加载中提示界面
    swiper---h5 跨域解决办法
    html5
  • 原文地址:https://www.cnblogs.com/Ly426/p/4717918.html
Copyright © 2011-2022 走看看