diff --git a/EF1.java b/EF1.java index 66ebb69..096f603 100644 --- a/EF1.java +++ b/EF1.java @@ -1,15 +1,20 @@ -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 - - } - } +public class EF1{ + + public static void main(String args[]){ + int n = Integer.parseInt(args[0]); + + class Factorial{ + public int Factorial(int m){ + if (m == 0){ + return 1; + } + else{ + return m*Factorial(m-1); + } + } + } + Factorial resultado = new Factorial(); + + System.out.println(resultado.Factorial(n)); + } } \ No newline at end of file diff --git a/EF2.java b/EF2.java index c70e201..c1bec6e 100644 --- a/EF2.java +++ b/EF2.java @@ -1,9 +1,35 @@ -public class EF2{ - - public static void main(String args[]){ - - - } - - -} \ No newline at end of file +public class EF2 { + + public static void main(String[] args) { + int[] array = {2, 3, 8, 109, 13, 4, 18, 10, 23, 18, 50, 11, 13, 2}; + EF2 bub = new EF2(); + bub.sort(array); + bub.print(array); + } + + public void sort(int array[]){ + + for (int i = 0 ; i < array.length ; i++) { + for (int j = 1 ; j < array.length-i ; j=(1+j)) { + if (array [j-1] > array[j]) { + int temp = array[j-1]; + array[j-1] = array[j]; + array[j] = temp; + } + } + } + } + + public void print (int array[]) { + System.out.print("{"); + for (int i = 0 ; i < array.length ; i++){ + System.out.print(array[i]); + if (i < array.length -1){ + System.out.print(", "); + } + else { + System.out.print("}"); + } + } + } +} diff --git a/EF4.java b/EF4.java index cb85211..64325df 100644 --- a/EF4.java +++ b/EF4.java @@ -1,30 +1,85 @@ -import javax.swing.JFrame; -import javax.swing.WindowConstants; - -public class EF4 extends JFrame{ - - 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); - - } - - public String getSuma(String entrada){ - String[] numeros = entrada.split(","); - int suma = 0; - //Realizar suma - for(String numero:numeros) - { - - } - return suma+""; - } - -} +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JFrame; +import javax.swing.WindowConstants; +import javax.swing.JTextField; +import javax.swing.JLabel; +import javax.swing.JButton; + +public class EF4 extends JFrame implements ActionListener{ + + public static void main(String args[]){ + EF4 ventana = new EF4(); + ventana.campoTexto(); + ventana.show(); + ventana.paintAll(ventana.getGraphics()); + + } + + public EF4(){ + setSize(250, 300); + setTitle("Sumadora"); + setLayout(null); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + setResizable(false); + + } + + private JTextField Campo; + private JLabel label1; + private JButton boton; + private JLabel label2; + + public void campoTexto(){ + Campo = new JTextField("0"); + Campo.setBounds(75,100,100,25); + Campo.setEditable(true); + Campo.setHorizontalAlignment(JTextField.RIGHT); + this.add(Campo); + + label1 = new JLabel(); + label1.setText("Ingrese los valores:"); + label1.setBounds(70, 60, 150, 25); + this.add(label1); + + boton = new JButton(); + boton.setText("Suma"); + boton.setBounds(75, 140, 100, 25); + boton.addActionListener(this); + this.add(boton); + + label2 = new JLabel(); + label2.setBounds(75, 180, 100, 25); + label2.setText(""); + this.add(label2); + + } + + @Override + public void actionPerformed(ActionEvent e){ + + String res = this.getSuma(Campo.getText()); + + label2.setText("Resultado: " + res); + } + + public String getSuma(String entrada){ + + String[] numeros = entrada.split(","); + + + int suma = 0; + //Realizar suma + int temp = 0; + for(String numero:numeros) + { + int a = Integer.parseInt(numero); + suma = temp + a; + temp = suma; + + } + return suma+""; + + } + +}