实现思路:输入一个半径的值,之后即可求出周长和面积:
代码举例:
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 ,
"请输入半径 : " , "计算" , 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);
}
}
public class mianji{
public static void main(String [] args)
{
double banjing = 14;//任意数
double s=3.14f*banjing*banjing;
double c=2*3.14f*banjing;
System.out.println("面积为:"+s);
System.out.println("周长为:"+c);
System.out.println("半径为:"+"banjing任意取值");
}
} 完全正确
我会哦,菜鸟题
public class Cir{
public static void main(String [] args)
{
int banjing=args[0];
float s=3.14f*banjing*banjing;
float c=2*3.14f*banjing;
System.out.println("面积为:"+s);
}
}
要传参数的为半径,文件名为Cir.java
public class Untitled1 {
public Untitled1() {
}
public static void main(String[] args) {
float r=1.0f;
float s=3.14f*r*r;
{
System.out.println("面积="+s);
}
float c=2*3.14f*r;
{
System.out.println("周长="+c);
}
}
}