- class GetSpace
- {
- public static void main(String [] args)
- {
- double a=7.5;
- double b=9;
- System.out.println(space(a,b));
- }
-
- public static double space(double a,double b)
- {
- if (a<=0 || b<=0) //对于double类型的值,可以为负,所以不用try ,判断就行。
- {
- throw new RuntimeException("矩形的边长要大于 0!");
- }
- return a*b;
- }
- }
复制代码
|