Climbing的专栏

Life is limited, but art is long

huang ClimbingID:hpdlzu80100
[修改头像]
1569次访问,排名2万外好友5人,关注者6
热爱生活,积极向上,流自己的汗,吃自己的饭!
hpdlzu80100的文章
原创 23 篇
翻译 0 篇
转载 2 篇
评论 0 篇
最近评论
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes
文章分类
收藏
    相册
    存档

    原创 自然对数e及e的x次方的计算(Calculation of natural exponent e and x power of e)

    新一篇: 170以内阶乘表(Factorial list up to 170)

     

    //Calculate natural exponent e and x power of e
    //used for Java learning practice
    import javax.swing.JOptionPane;
    public class Exponent_e {
        
    static double exponent=1.0;
        
    static double exponentx=1.0;
        
        
    public static double Factorial (int argument)
        
    {
        
    double factorial=1;
        
    if (argument<0)
        JOptionPane.showMessageDialog(
    null"Please input a nonegative integer",
                
    "Expoent e Calculation",JOptionPane.ERROR_MESSAGE);
        
    else {
          
    if (argument==0)
          factorial
    =1;
          
    else if (argument>0
          
    {
            factorial
    =1;
             
    for (int i=1;i<argument+1;i++)
            factorial
    *=i;
          }

             }

        
    return factorial;
         }

        
        
    public static int Productx(int base, int argument)
        
    {
            
    int productx=1;
            
    for (int i=1;i<argument+1;i++)
                productx
    *=base;
            
    return productx;
        }

        
    public static void main(String args[])
    {
        String N,Base;
        
    int n;
        
    int base;
        N
    =JOptionPane.showInputDialog("Enter an integer N:");
        n
    =Integer.parseInt(N);
        Base
    =JOptionPane.showInputDialog("Enter an integer X:");
        base
    =Integer.parseInt(Base);
        
        
    if (n<0)
            JOptionPane.showMessageDialog(
    null"Please input a nonegative integer",
                    
    "Expoent e Calculation",JOptionPane.ERROR_MESSAGE);
        
    else
            
    {for (int i=1;i<n+1;i++)
            
    {exponent+=1.0/Factorial(i);
        exponentx
    +=Productx(base,i)/Factorial(i);}

        
        JOptionPane.showMessageDialog(
    null"Calculated exponent e and x power of e are:"+exponent+
                
    " and "+exponentx,"Expoent e Calculation",JOptionPane.INFORMATION_MESSAGE);}

    }

    }

    发表于 @ 2008年04月08日 11:51:00|评论(loading...)|编辑

    旧一篇: 数组排序的Java实现(Sorting of arrays implemented with Java)

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © Climbing