>

jueves, 4 de abril de 2013

Teorema de Pitagoras en JAVA [POO] c0d3 by R4z0R

/*


escriba un codigo en java que calcule catetos e hipotenusa por teorema de pitagoras

*/



import java.util.*;
public class pitagoras {
public Scanner lea = new Scanner (System.in);
public double a, b, c, x;


public static void main (String[]args) {
Scanner capture = new Scanner (System.in);
pitagoras objeto = new pitagoras();
objeto.banner();
System.out.println (" ####  Teorema de Pitagoras  ####");
System.out.println ("¿Que Desea Hallar?");
System.out.println ("1) Hipotenusa");
System.out.println ("2) Cateto A");
System.out.println ("3) Cateto B");

int opc = capture.nextInt();

switch (opc) {
case 1:
objeto.hipotenusa();
break;
case 2:
objeto.catetoA();
break;
case 3:
objeto.catetoB();
break;
default: System.out.println ("Opcion No valida");

}


}  /* fin void main */


public void banner() {
System.out.println ("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
System.out.println ("-=-                     ##                    -=-");
System.out.println ("-=-  Teorema           #  #                   -=-");
System.out.println ("-=-                 a #    # b                -=-");
System.out.println ("-=-        de        #      #                 -=-");
System.out.println ("-=-                 ##########  Pitagoras     -=-");
System.out.println ("-=-                      c                    -=-");
System.out.println ("-=-   /////////////////////////////////////   -=-");
System.out.println ("-=-            c0d3 by @r4z0r_bl4ck           -=-");
System.out.println ("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");

}

public void hipotenusa() {
System.out.println ("Ingrese el cateto A");
a = lea.nextDouble();
System.out.println ("Ingrese el cateto B");
b = lea.nextDouble();
x = ((a*a)+(b*b));
c = Math.sqrt(x);
System.out.println ("La Hipotenusa del triangulo es: " +c);
}

public void catetoA() {
System.out.println ("Ingrese el cateto B");
b = lea.nextDouble();
System.out.println ("Ingrese La Hipotenusa");
c = lea.nextDouble();
x = ((c*c)-(b*b));
a = Math.sqrt(x);
System.out.println ("El Cateto A del triangulo es: " +a);
}
public void catetoB() {
System.out.println ("Ingrese el cateto A");
a = lea.nextDouble();
System.out.println ("Ingrese La Hipotenusa");
c = lea.nextDouble();
x = ((c*c)-(a*a));
b = Math.sqrt(x);
System.out.println ("El Cateto B del triangulo es: " +b);
}



}  /* fin class */


=================================================

c0d3r by @R4Z0R

No hay comentarios:

Publicar un comentario