import math
r=float(input('请输晌拦闷入圆的半径:'))
print('半衡肢径为%f的圆的面积为宴弯%10.2f'%(r,math.pi*r*r))
import java.util.Scannerclass NotRectangleException extends Exception
{
public NotRectangleException(String msg)
{
super(msg)
}
}
class MyRectangle
{
private float x
private float y
private float z
public MyRectangle()
{
}
public MyRectangle(float a, float b, float c)
{
x = a
y = b
z = c
}
public void getArea()
{
try{
isRect()
}catch(NotRectangleException ne){
System.out.println("自定义异常类:" + ne.getMessage())
return
}
float p = (x + y + z)/2.0f
System.out.println("简伏三角形的面积: " + Math.sqrt(p*(p-x)*(p-y)*(p-z)) + "(单位)")
}
public void showInfo()
{
try{
isRect()
System.out.println("三角形的三边分别为:春咐薯x = " + x + " y = " + y + " z = " + z)
}catch(NotRectangleException ne){
System.out.println("自定义异常类:" + ne.getMessage())
}
}
public boolean isRect() throws NotRectangleException
{
if(x+y>z &&x+z>y &&y+z>x)
{
return true
}
else {
throw new NotRectangleException("x = " + x + ",y = " + y + "扒者,z = " + z + "不能构成三角形!\n")
}
}
}
public class MyRectangleTest
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in)
System.out.print("请输入三角形的三条边:")
float a = scan.nextFloat()
float b = scan.nextFloat()
float c = scan.nextFloat()
MyRectangle mr = new MyRectangle(a, b, c)
System.out.println("\n若三条边能组成的三角形->则面积: ")
mr.getArea()
System.out.println("\n显示三条边的信息: ")
mr.showInfo()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)