用java 编写一个程序,要求输入圆的半径,求圆的周长,面积.

来源:百度知道 编辑:UC知道 时间:2024/05/21 11:46:51
请用java 编写一个程序,要求输入圆的半径,求圆的周长,面积.
并输出结果.

PS:本人是初学者.
回复:冷雨冰燕
谢了! 我用的是eclipse ,你的程序代码有点问题啊!
就显示这些东西:
Exception in thread "main" java.lang.Error: 无法解析的编译问题:
类型不匹配:不能从 String 转换为 int

实现思路:输入一个半径的值,之后即可求出周长和面积:
代码举例:
import javax.swing.JOptionPane;
class account
{
public static void main(String[] args)
{
String radiusString = JOptionPane.showInputDialog(null ,
"请输入半径 : " , "计算" , JOptionPane.QUESTION_MESSAGE);
double radius = Double.parseDouble(radiusString);
double c;
double area;
final double PI = 3.14159;//定义圆周率π的值
c = 2 * PI * radius; //计算周长
area = radius * radius * PI;//计算面积
//输出结果
JOptionPane.showMessageDialog(null ,
"周长是 : " + c + "\n" + "面积是 : " + area ,
"outputNumber" , JOptionPane.INFORMATION_MESSAGE);
}
}

已经测试过了

import javax.swing.JOptionPane;

class account
{
public static void main(String[] args)
{
String radiusString = JOptionPane.showInputDialog(null ,
"请输入半径 : " , "计算" , JO