Está en la página 1de 3

FACTORIAL

package factorial2;

public class Factorial {
private int numero;

public Factorial(int numero){
this.numero = numero;
}

public int Fact(int num){
int fact = 1;
for(int i =1; i <=num; i++){
fact*=i;
}
return fact;
}
}



package factorial2;

import javax.swing.JOptionPane;

public class Factorial2 {


public static void main(String[] args) {
int n = Integer.parseInt(JOptionPane.showInputDialog("Ingrese un nmero"));

Factorial f = new Factorial(n);
int fact = f.Fact(n);

JOptionPane.showMessageDialog(null, "El factorial es: " + fact);
}

}



EJERCICIO 3

package Modelo;

import javax.swing.JOptionPane;

public class Suma {

public static void main(String[] args) {
int N, M, cf, cc, A[][] = new int[50][50], suma = 0;
String texto = "Matriz A\n";
N = Integer.parseInt(JOptionPane.showInputDialog("Ingrese la cantidad de filas"));
M = Integer.parseInt(JOptionPane.showInputDialog("Ingrese la cantidad de columnas"));
for (cf = 0; cf <= N - 1; cf++) {
for (cc = 0; cc <= M - 1; cc++) {
A[cf][cc] = Integer.parseInt(JOptionPane.showInputDialog(texto));
texto = texto + A[cf][cc] + " ";
}
texto = texto + "\n";
}

for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
suma = suma + A[i][j];
}
}
JOptionPane.showMessageDialog(null, "La suma es: " + suma);
}
}ooooooooooooooooooooooooooooo