JAVA编程中求圆的面积怎么写?
import java.util.Scanner;
//java 并不直接支持控制台输入,但可以使用Scanner类建立它的对象,已读取来System.in的输入
public class KongZhi {
public static void main(String[] args) {
Scanner input = new Scanner( System.in);
System.out.println("Enter a number for radius: ");
double radius = input.nextDouble();
double area= radius*radius*3.14;
System.out.println("The area for the circle of radius "+radius+" "+area);
}
}
扩展资料:
其他方法求圆的面积:
#include<stdio.h>
#include<math.h>
#define M=3.14
int main()
{
int r;
double s;
scanf("%d",&r);
s=M*pow(r,2);
printf("%0.7lf",s);
return 0;
}
2022-12-05 广告
JAVA编程中求圆的面积代码如下:
import java.util.Scanner;
public class yuan {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int r;
float area,perimeter;
final float PI=3.14f;
System.out.println(“请输入圆的半径: “);
Scanner sc=new Scanner(System.in);
r=sc.nextInt();
area=PI*r*r;
perimeter=2*PI*r;
System.out.println(“圆的面积是:”+area);
System.out.println(“圆的周长是 “+perimeter);
}
}
扩展资料:
JAVA编程中求圆的面积的其他代码:
package com.wxh;
import java.math.BigDecimal;
import java.util.Scanner;
public class RoundArea {
private static final String PI="3.14159265358979323";
public static void main(String[] args) {
BigDecimal p=new BigDecimal(PI);
Scanner sc=new Scanner(System.in);
int r=sc.nextInt();
BigDecimal r1=new BigDecimal(r);
BigDecimal area=p.multiply(r1).multiply(r1);
area=area.setScale(7, BigDecimal.ROUND_HALF_UP);
System.out.println(area.toString());
}
}
JAVA编程中求圆的面积如下:
import java.util.*;
public class Circle
{
public static void main(String[] args)
{
double r;
System.out.print("输入圆的半径:");
Scanner s=new Scanner(System.in);
r=s.nextDouble();
double S=Math.PI*r*r;
System.out.print("面积为:"+S);
}
}
扩展资料:
圆的面积公式:S=πr^2或S=π*(d/2)^2。
圆的半径:r
直径:d
圆周率:π(数值为3.1415926至3.1415927之间……无限不循环小数),通常采用3.14作为π的数值。
因此,圆的面积只需要用圆的半径的平方乘以3.14即可。
参考资料:百度百科-圆面积
public class Circle
{
public static void main(String[] args)
{
double r;
System.out.print("输入圆的半径:");
Scanner s=new Scanner(System.in);
r=s.nextDouble();
double S=Math.PI*r*r;
System.out.print("面积为:"+S);
}
}
2013-04-14
import java.util.*;
abstract class VolumeArea {
double pi = 3.14169;
abstract float volume(double r);
abstract float area(double r);
}
public class VolumeAndArea extends VolumeArea {
public static void main(String[] args) throws IOException {
Scanner cin = new Scanner(System.in);
System.out.print("Please input the radius : ");
double r = cin.nextDouble();
VolumeAndArea x = new VolumeAndArea();
System.out.println("The volume is : " + x.volume(r));
System.out.println("The area is : " + x.area(r));
}
float volume(double r) {
return (float) (4 * pi * r * r * r / 3);
}
float area(double r) {
return (float) (pi * r * r);
}
}