diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7aa0cb8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +EF1.class +EF2.class +EF4.class \ No newline at end of file diff --git a/EF1.java b/EF1.java index 66ebb69..10633c7 100644 --- a/EF1.java +++ b/EF1.java @@ -1,15 +1,13 @@ public class EF1{ - public static void main(String args[]){ - int n = Integer.parseInt(args[0]); - System.out.println(Factorial(n)); - } - - public static int Factorial(int n){ - if(){//Escribir condición de salida - return 1; - }else{//Escribir el retorno para la recursividad + int numero = Integer.parseInt(args[0]); + System.out.println(Factorial(numero)); + } + public static int Factorial(int numero){ + if(numero==1 || numero==0){ + return 1; + }else{return numero*Factorial(numero-1); } } -} \ No newline at end of file +} diff --git a/EF2.java b/EF2.java index c70e201..bcadf81 100644 --- a/EF2.java +++ b/EF2.java @@ -1,9 +1,31 @@ -public class EF2{ - - public static void main(String args[]){ - - - } +public class EF2 { + public static void main(String[] args) { + int arr[] = {2, 3, 8, 109, 13, 4, 18, 10, 23, 18, 50, 11, 13, 2}; + EF2 arreglo = new EF2(); + arreglo.sort(arr); + arreglo.imprimir(arr); + } + public void sort(int arr []){ + for(int i = 0; i < (arr.length); i++){ + for (int j = 1; j < (arr.length-i);j++){ + if (arr[j-1] > arr [j]){ + int temp = arr [j]; + arr [j] = arr [j-1]; + arr [j-1] = temp; + } + } + } + } + + public void imprimir(int arr []){ + System.out.print("{"); + for (int i = 0; i < arr.length ; i++){ + System.out.print(arr[i]); + if (i!=(arr.length-1)) { + System.out.print(","); + } + } + System.out.println("}"); - +} } \ No newline at end of file diff --git a/EF4.java b/EF4.java new file mode 100644 index 0000000..9ba1ab4 --- /dev/null +++ b/EF4.java @@ -0,0 +1,57 @@ +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; + +public class EF4 extends JFrame implements ActionListener{ + + public JButton btnBotonSumar = new JButton("SUMAR"); + public JLabel lblNumeros = new JLabel("INGRESE NUMEROS : "); + public JTextField txtNumeros = new JTextField(20); + public JLabel lblResultado = new JLabel(); + + public static void main(String args[]){ + EF4 ventana = new EF4(); + ventana.show(); + } + + public EF4(){ + setSize(250, 300); + setTitle("Sumadora"); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + setResizable(false); + this.btnBotonSumar.addActionListener(this); + FlowLayout DISTRIBUIDOR = new FlowLayout(FlowLayout.CENTER,30,30); + this.setLayout(DISTRIBUIDOR); + this.add(this.lblNumeros); + this.add(this.txtNumeros); + this.add(this.btnBotonSumar); + this.add(this.lblResultado); + } + + public String getSuma(String entrada){ + String[] numeros = entrada.split(","); + int suma = 0; + //Realizar suma + for(String numero:numeros) + { + suma += Integer.parseInt(numero); + } + return "Resultado:" +suma+ ""; + } + + @Override + public void actionPerformed(ActionEvent AE) + { + if(AE.getSource() == this.btnBotonSumar) + { + String entrada = txtNumeros.getText(); + lblResultado.setText(getSuma(entrada)); + } + + } +} \ No newline at end of file