• Lenguaje

    Java usando Swing

  • Descripción

    Obtener una función exponencial, la cual está dada por:
    e^x = 1+x/1! + x²/2! + x³/3! + ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class FuncionExponencial extends JFrame implements ActionListener {

    private static final long serialVersionUID = 1L;
    private JButton button;

    public Algoritmo() {
        button = new JButton("Procesar");
        Container pane = getContentPane();
        pane.setLayout(new BorderLayout());
        JPanel panel, subpanel;
        panel = new JPanel(new FlowLayout());
        panel.add(button);
        pane.add(panel);
        button.addActionListener(this);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();
        setLocationRelativeTo(null);
    }

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
        int n;
        double ex, factorial, x;
        if(i==1)
        {
            ex=1;
            factorial=1;
        }
        factorial=factorial*i;
        ex=ex+Math.pow(x,i)/factorial;
        pack();
    }

    public static void main(String[] args) {
        new Algoritmo().setVisible(true);
    }

}