public class Pitagoras {
private double hipotenusa;
private int cateto1;
private double cateto2;
public Pitagoras(int c1,double c2){
this.cateto1=c1;
this.cateto2=c2;
}
public Pitagoras(double h, int c1){
this.hipotenusa=h;
this.cateto2=c1;
}
public double getHipotenusa(){
double hipotenusa;
hipotenusa=(Math.sqrt(this.cateto1*this.cateto1)+(this.cateto2*this.cateto2));
return( hipotenusa);
}
public double getCateto(){
double cateto;
cateto=(Math.sqrt(this.hipotenusa*this.hipotenusa)-(this.cateto1*this.cateto1));
return( cateto);
}
}
iNICIo:
public class Inicio{
public static void main (String [] w){
Pitagoras p1= new Pitagoras (50,15.0);
System.out.println("la hipotenusa es"+ (p1.getHipotenusa()));
Pitagoras p2= new Pitagoras (30.0,15);
System.out.println("el cateto es"+ (p2.getCateto()));
}
}
No hay comentarios:
Publicar un comentario