La Clase circulo
metodo area
metodo perimetro
metodo imprimir
_________________________________________________________________________________________
public class Circulo {
static final double PI=3.1416;
public double area(double radio){
double area=PI*radio*radio;
return area;
}
public double perimetro(double radio){
double perimetro=PI*(radio*2);
return perimetro;
}
public void imprimir(double a,double p){
System.out.println("El perimetro del circulo es: "+p);
System.out.println("El area del circulo es: "+a);
}
}
___________________________________________________________________________________________
import java.util.Scanner;
public class Tcirculo {
public static void main(String[] args) {
double radio=0;
double a=0;
double p=0;
Scanner read= new Scanner(System.in);
System.out.println("Radio del circulo: ");
radio=read.nextDouble();
Circulo obj= new Circulo();
a=obj.area(radio);
p=obj.perimetro(radio);
obj.imprimir(a,p);
}
}
No hay comentarios:
Publicar un comentario