Académique Documents
Professionnel Documents
Culture Documents
CURSO: 1062284
VARIABLES Y ESTRUCTURAS DE CONTROL EN LA PROGRAMACIN
ORIENTADA A OBJETOS: JAVA
TUTOR:
FABIO RICARDO CHARRY SANCHEZ
OBJETIVOS
DESARROLLO
ACTIVIDAD
Haz un applet que te calcule el factorial de un nmero N, el
cual te dar el usuario, el factorial de un nmero N, definido
matemticamente como N! se obtiene como la multiplicacin
de todos los nmeros que estn desde el 1 hasta el N = 1 * 2
* 3 * ..... (N-2) * (N-1) * N, como se muestra en la figura, por
definicin el factorial de 0 es 1
public class AppletFactorial extends Applet implements ActionListener {
Label l1, l2;TextField num, fac;Button cal;
@Override
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported
yet."); //To change body of generated methods, choose Tools |
Templates.
}
public AppletFactorial(){
l1 = new Label ("Numero");
num = new TextField (4);
l2 = new Label ("Factorial");
fac = new TextField(5);
cal = new Button("Calcular");
add(l1);
add(num);
add(cal);
add(l2);
add(fac);
cal.addActionListener(this);
}
}
private void calActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int numero = Integer.parseInt(num.getText());
int fact = 1;
for (int i = 1; i <= numero; i++){
fact = fact * i;
}
fac.setText("" + fact);
}
BIBLIOGRAFIA
http://www.javaya.com.ar/detalleconcepto.php?codigo=84&inicio=