package com.t1; import java.util.*; class Circle { double r; Circle(double a){ r=a; }//构造函数,将参数传给r double getArea(){ double S=3.14*r*r; return S; } //普通方法,计算圆面积 } class Yuanzhu{ double heigh; Circle circle;//初始化对象 Yuanzhu(double b){ heigh=b; } double s=circle.getArea();//获取Circle中的getArea计算出的底面积 !!!运行报错 double getVolue(){ double v=s*heigh; return v; }//计算体积 } public class Test{ public static void main(String[] args){ Scanner input=new Scanner(System.in); System.out.println("请输入圆柱的底面半径r"); double x=input.nextDouble(); Circle circle=new Circle(x); System.out.println("请输入圆柱的高h"); double y=input.nextDouble(); Yuanzhu yuanzhu=new Yuanzhu(y); double S=circle.getArea(); double V=yuanzhu.getVolue(); System.out.println("圆柱的底面积是"+S+"圆柱的体积是"+V); } }
编译时没有出错,可是运行时输入半径和高之后就出错了,这是怎么回事?求高手解答,谢谢~~
慕的地6079101
hainishishui
bj藏锋
相关分类