martes, 10 de marzo de 2009

Taller#2 ejemplo2

  • El cuadrante de un punto (x,y) se puede determinar a partir del signo de x e y, Escribir una función tal que dadas las coordenadas x e y, indique a qué cuadrante pertenece el punto.
//Declaramos las variables
String txt1 = "", txt2 = "", txt = "";
int x = 0, y = 0;

//Capturamos los datos
txt1 = JOptionPane.showInputDialog(null, "Ingrese la coordenada X",
"Plano Cartesiano", JOptionPane.INFORMATION_MESSAGE);
txt2 = JOptionPane.showInputDialog(null, "Ingrese la coordenada Y",
"Plano Cartesiano", JOptionPane.INFORMATION_MESSAGE);

//Convertimos de String a Integer (Entero)
x = Integer.parseInt(txt1);
y = Integer.parseInt(txt2);

//Realizamos la comparacion para ver en que cuadrante del plano pertenece
if (x > 0){
if (y > 0){
txt = "Cuadrante I";
}else if(y < txt = "Cuadrante IV" style="color: rgb(153, 0, 0);">else if
(x < style="color: rgb(153, 0, 0);">if (y > 0){
txt = "Cuadrante II";
}else if(y < txt = "Cuadrante III" style="color: rgb(153, 0, 0);">if (x == 0){ if (y > 0){
txt = "Cuadrante I y II";
}else if(y < txt = "Cuadrante III y IV" style="color: rgb(153, 0, 0);">else if (y == 0){
if (x > 0){
txt = "Cuadrante I y IV";
}else if(x < txt = "Cuadrante II y III" style="color: rgb(153, 0, 0);">if (x == 0 && y == 0){
txt="Neutro";
}

//Imprimimos el resultado
JOptionPane.showMessageDialog(null, txt,
"Plano Cartesiano", JOptionPane.INFORMATION_MESSAGE);

No hay comentarios:

Publicar un comentario