計算圓的面積程式碼

运气不沾边發表於2024-09-28

package z2;
import java.io.;
public class Lao{
final float PI=3.14159f;
float r;
public void setRadius(float r1)
{
r=r1;
}
public float getRadius()
{
return r;
}
public float getArea()
{
return PIr*r;
}
public static void main(String[] args){
Lao c1=new Lao();
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
String str=null;
float rr;
System.out.println("請輸入圓的半徑:");
try{
str =br.readLine();
}catch (IOException e){
e.printStackTrace();
}
rr=Float.parseFloat(str);
c1.setRadius(rr);
float Area=c1.getArea();
System.out.println("圓的半徑="+c1.getRadius()+"面積="+Area);
}
}

相關文章