python编程在线求助

python编程在线求助,第1张

import math

r=float(input('请输晌拦闷入圆的半径:'))

print('半衡肢径为%f的圆的面积为宴弯%10.2f'%(r,math.pi*r*r))

import java.util.Scanner

class 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()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12531613.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存