Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TareaFinal_201602918 #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions EF1.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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 static int factorial(int num){
if(num<1){
return(1);
}
else{
return(factorial(num-1)*num);
}
}

public static void main(int args[]){
int num=0;
args[0]=num;
System.out.println(factorial(num));
}
}
36 changes: 30 additions & 6 deletions EF2.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
public class EF2{

public static void main(String args[]){


}
public static void main(String[] args){
int array[]= {2,3,8,109,13,4,18,10,23,18,50,11,13,2};
EF2 ef = new EF2();
ef.sort(array);
ef.print(array);
}


public void sort(int array[]){
for(int i=0; i<=array.length; i++){
for(int j=1; j<array.length; j++){
if(array[j-1]>array[j]){
int temp = array[j];
array[j] = array[j-1];
array[j-1] = 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(",");
}
}
System.out.println("}");

}
}
89 changes: 89 additions & 0 deletions EF4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

public class EF4 extends JFrame{

private JPanel contentPane;
private JTextField texto;
private JLabel sum;
private JLabel result;
private JLabel insert;
private JButton operar;

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.contentPane = (JPanel) getContentPane();
this.contentPane.setSize(250,300);
this.contentPane.setLayout(null);

texto = new JTextField();
texto.setBounds(20,50,200,25);
contentPane.add(texto);

insert = new JLabel();
insert.setText("Ingrese Numeros Separados por coma");
insert.setBounds(05,10,220,20);
contentPane.add(insert);

sum = new JLabel();
sum.setText("Suma:");
sum.setBounds(75,200,50,20);
contentPane.add(sum);

result = new JLabel();
result.setBounds(130,200,100,20);
contentPane.add(result);

operar = new JButton("Operar");
operar.setBounds(60,100,125,30);

operar.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent evt){

operar(evt);
}
});
contentPane.add(operar);
}


public String getSuma(String entrada){
String[] numeros = entrada.split(",");
int suma = 0;
//Realizar suma
try{
for(String numero:numeros)
{
suma += Integer.parseInt(numero);
}
return suma+"";
}
catch(NumberFormatException m){
return "Ingrese numeros";
}
}

public void operar(ActionEvent evt){
String entrada = texto.getText();
result.setText(getSuma(entrada));
}

}