第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

怎樣定義一個(gè)圓類,成員變量是圓心和半徑,方法是求周長和面積

怎樣定義一個(gè)圓類,成員變量是圓心和半徑,方法是求周長和面積

正在回答

8 回答

package com.imooc;


import java.util.Scanner;


public class Circle {

/*

* 關(guān)于圓的計(jì)算問題:

*

* */

final double PI=3.14;//用final修飾,代表常量值,不可改變

//創(chuàng)建一個(gè)輸入的對(duì)象、動(dòng)態(tài)給定值(因?yàn)橛袃蓚€(gè)方法,將這個(gè)定成全局的)

Scanner sc=new Scanner(System.in);

public static void main(String[] args) {

//實(shí)例化對(duì)象

Circle cl=new Circle();

//調(diào)用方法執(zhí)行

cl.getZC();//計(jì)算周長

cl.getAcreage();//計(jì)算面積

}

//創(chuàng)建一個(gè)計(jì)算的周長的方法(2*PI*r)

public void getZC(){

//提示輸入

System.out.println("請(qǐng)輸入圓的半徑:");

//定義圓的半徑

int r=sc.nextInt();

//定義一個(gè)變量計(jì)算周長

double zc=2*PI*r;

System.out.println("圓的周長為:"+zc);

}

//創(chuàng)建一個(gè)計(jì)算半徑的方法

public void getAcreage(){

//提示輸入

System.out.println("請(qǐng)輸入圓的半徑:");

//定義圓的半徑

int r=sc.nextInt();

//定義一個(gè)變量計(jì)算周長

double Acreage=PI*r*r;

System.out.println("圓的面積為:"+Acreage);

}


}


0 回復(fù) 有任何疑惑可以回復(fù)我~

public class Circle {
? ?private double radius;

? ?public Circle(double radius) {
? ? ? ?this.radius = radius;
? ?}

? ?public double getPerimeter() {
? ? ? ?return 2 * Math.PI * radius;
? ?}

? ?public double getArea() {
? ? ? ?return Math.PI * radius * radius;
? ?}
? ?
? ?public static void main(String[] args) {
? ? ? ?Circle c = new Circle(1.28);
? ? ? ?System.out.printf("圓的周長: %.2f\n", c.getPerimeter());
? ? ? ?System.out.printf("圓的面積: %.2f\n", c.getArea());
? ?}
}

0 回復(fù) 有任何疑惑可以回復(fù)我~
import?java.io.PipedInputStream;

import?org.omg.CORBA.PUBLIC_MEMBER;

public?class?Circle?{

	public?static?void?main(String[]?args)?{
		//?怎樣定義一個(gè)圓類,成員變量是圓心和半徑,方法是求周長和面積
		int?R?=?8;
		double?Pi?=?3.14;
		Circle?circle?=?new?Circle();
		System.out.println("周長:?"?+?circle.zhouchang(R,?Pi));
		System.err.println("面積:?"?+?circle.mianji(Pi,?R));
		
	}
	public?double?zhouchang(int?R,?double?Pi)?{
		double?zhouchang?=?2?*?R??*?Pi;
		return?zhouchang;
	}
	public?double?mianji(double?Pi,?int?R)?{
		double?mianji?=?Pi?*?R?*?R;
		return?mianji;
		
	}
	
}


0 回復(fù) 有任何疑惑可以回復(fù)我~

public class Yuan

{


? ? public static void main(String[] args)

? ? {

? ? ? ? // TODO 自動(dòng)生成的方法存根

? ? ? ? double r=4;// 半徑


? ? ? ? double L=2 * Math.PI * r;

? ? ? ? double S=Math.PI * r * r;

? ? ? ? System.out.println("圓周長是:" + L);

? ? ? ? System.out.println("圓面積是:" + S);


? ? }


}


0 回復(fù) 有任何疑惑可以回復(fù)我~



package com.basic;

import com.basic.InnerClass.Inner;

/**
?* 圓類,以圓心和半徑來區(qū)分兩個(gè)圓是否相同。
?*
?* @author Administrator
?*/
public class Circle
{
??? private static final int CONSTANT_TWO = 2;

??? /**
???? * 圓心
???? */
??? private String centerPoint;
??? /**
???? * 半徑
???? */
??? private double radius;

??? /**
???? * 無參構(gòu)造器
???? */
??? public Circle()
??? {
??? }

??? /**
???? * 有參構(gòu)造器
???? *
???? * @param centerPoint
???? *??????????? 圓心(可以繼續(xù)封裝成坐標(biāo))
???? * @param radius
???? *??????????? 半徑
???? */
??? public Circle( String centerPoint,double radius )
??? {
??????? super();
??????? this.centerPoint = centerPoint;
??????? this.radius = radius;
??? }

??? /**
???? * 獲取圓心值
???? *
???? * @return 圓心值
???? */
??? private String getCenterPoint()
??? {
??????? return centerPoint;
??? }

??? /**
???? * 設(shè)置圓心值
???? *
???? * @param centerPoint
???? */
??? private void setCenterPoint( String centerPoint )
??? {
??????? this.centerPoint = centerPoint;
??? }

??? /**
???? * 獲取圓半徑
???? *
???? * @return
???? */
??? private double getRadius()
??? {
??????? return radius;
??? }

??? /**
???? * 設(shè)置圓半徑
???? *
???? * @param radius
???? */
??? private void setRadius( long radius )
??? {
??????? this.radius = radius;
??? }

??? /**
???? * 計(jì)算圓周長
???? *
???? * @return
???? */
??? public double caculatePerimeter()
??? {
??????? return Math.PI * this.radius * CONSTANT_TWO;
??? }

??? /**
???? * 計(jì)算圓面積
???? *
???? * @return
???? */
??? public double caculateArea()
??? {
??????? return Math.PI * this.radius * this.radius;
??? }

??? /**
???? * 重寫圓類的toString方法
???? */
??? @Override
??? public String toString()
??? {
??????? return "Circle [centerPoint=" + centerPoint + ", radius=" + radius
??????????????? + "]";
??? }

??? @Override
??? public int hashCode()
??? {
??????? final int prime = 31;
??????? int result = 1;
??????? result = prime * result
??????????????? + ((centerPoint == null) ? 0 : centerPoint.hashCode());
??????? long temp;
??????? temp = Double.doubleToLongBits( radius );
??????? result = prime * result + (int)(temp ^ (temp >>> 32));
??????? return result;
??? }

??? @Override
??? public boolean equals( Object obj )
??? {
??????? if ( this == obj )
??????????? return true;
??????? if ( obj == null )
??????????? return false;
??????? if ( getClass() != obj.getClass() )
??????????? return false;
??????? Circle other = (Circle)obj;
??????? if ( centerPoint == null )
??????? {
??????????? if ( other.centerPoint != null )
??????????????? return false;
??????? } else if ( !centerPoint.equals( other.centerPoint ) )
??????????? return false;
??????? if ( Double.doubleToLongBits( radius ) != Double
??????????????? .doubleToLongBits( other.radius ) )
??????????? return false;
??????? return true;
??? }

??? public static void main( String[] args )
??? {
??????? Circle circle = new Circle( "a1", 10 );
??????? System.out.println( circle );

??????? double perimeter = circle.caculatePerimeter();
??????? System.out.println( circle + "的周長為:" + perimeter );

??????? double area = circle.caculateArea();
??????? System.out.println( circle + "的面積為:" + area );
??? }
}



1 回復(fù) 有任何疑惑可以回復(fù)我~

import java.util.Scanner;

public class HelloWorld {

?? ?public static void main(String[] args) {
?? ??? ?double π = 3.14;
?? ??? ?double r;
?? ??? ?double l;
?? ??? ?double s;
?? ??? ?Scanner sc = new Scanner(System.in);
?? ??? ?sc.useDelimiter("\n");
?? ??? ?while(sc.hasNext()){
?? ??? ??? ?r=Double.parseDouble(sc.nextLine());
?? ??? ??? ?l=2*Math.PI*r;;
?? ??? ??? ?s=Math.PI*r*r;;
?? ??? ??? ?System.out.println("周長是:" + l);
?? ??? ??? ?System.out.println("面積是:" + s);
?? ??? ?}
?? ??? ??? ?
?? ?}
?? ?
}

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

森特

前面定義的π可以刪了,多寫了
2016-04-12 回復(fù) 有任何疑惑可以回復(fù)我~

class A{

????????private float r;

????????public float getR(){

????????return r;

????????}

????????public void setR(float r){

????????this.r = r;

????????}

????????public float Area(){

????????return (float)(3.14*r*r);

????????}

????????public float Circumf(){

????????return (float)3.14*2*r;

????????}

}

public class Circle {

????????public static void main(String[] args) {

????????A a = new A();

????????a.setR(4);

????????System.out.println(a.Area());

????????System.out.println(a.Circumf());

????????}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

//創(chuàng)建圓型類

class ?circle?

{ ??

//創(chuàng)建 ?算周長方式 傳出半徑算周長

?????public double void setPerimeter(?double?radii??)

?????{?

? ?//

? ? ? ?double?π = 3.14159265358979323846;

? ? ? ?double?perimeter=?radii *2*π ;

? ? ? ?retuan?perimeter ;

? ? ?}

//創(chuàng)建 ?算周長方式 傳出半徑算面積

public double void setAcreage(?double?radii??)

?????{ ?double?π = 3.14159265358979323846;

? ? ? ?double?acreage=?radii *radii?*π ;

? ? ? ?retuan?acreager ;

? ? ?}

}

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

怎樣定義一個(gè)圓類,成員變量是圓心和半徑,方法是求周長和面積

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)