lunes, 9 de marzo de 2009

Laboratorio3 ejemplo7

  • Se ingresan 3 lados de un triangulo al computador para determinar si el triangulo existe.
Triangulo


//Declaracion de variables
String txt1 = "", txt2 = "", txt3 = "", txt = "";
int n1 = 0, n2 = 0, n3 = 0;

//Captura de datos
txt1 = JOptionPane.showInputDialog(null, "Ingrese el primer dato",
"Triangulo", JOptionPane.INFORMATION_MESSAGE);
txt2 = JOptionPane.showInputDialog(null, "Ingrese el segundo dato",
"Triangulo", JOptionPane.INFORMATION_MESSAGE);
txt3 = JOptionPane.showInputDialog(null, "Ingrese el tercer dato",
"Triangulo", JOptionPane.INFORMATION_MESSAGE);

//Convertir datos a Integer(Entero)
n1 = Integer.parseInt(txt1);
n2 = Integer.parseInt(txt2);
n3 = Integer.parseInt(txt3);

//Verificamos a que tipo de triangulo corresponde
if(n1 == n2){
if(n1 == n3){
txt = "Triangulo Equilatero";
}else if(n1 != n3){
txt = "Triangulo Isosceles";
}
}else if(n1 == n3){
if(n1 != n2){
txt = "Triangulo Isosceles";
}
}else if(n2 == n3){
if(n2 != n1){
txt = "Triangulo Isosceles";
}
}
if(n1 != n2 && n2 != n3 && n1 != n3){
txt = "Triangulo Escaleno";
}

//Imprimimos los resultados
JOptionPane.showMessageDialog(null, "" + txt,
"Triangulo", JOptionPane.INFORMATION_MESSAGE);

No hay comentarios:

Publicar un comentario