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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

思考題練習(xí)

package?com.imooc;

public?abstract?class?Shape?{
???public?abstract?void?perimeter();//求周長
???public?abstract?void?area();//求面積
???
}
package?com.imooc;
import?java.util.Scanner;
public?class?Rectangle?extends?Shape?{
????
???
????
	public?void?perimeter()?{
		Scanner?input?=?new?Scanner(System.in);
		System.out.println("請輸入矩形的寬:");
		float?width?=?input.nextFloat();
		System.out.println("請輸入矩形的長:");
		float?length=input.nextFloat();
		System.out.println("矩形的周長為:"+2*(width+length));

	}

	public?void?area()?{
		Scanner?input?=?new?Scanner(System.in);
		System.out.println("請輸入矩形的寬:");
		float?width=input.nextFloat();
		System.out.println("請輸入矩形的長:");
		float?length=input.nextFloat();
		?System.out.println("矩形的面積為:"+width*length);

	}

}
package?com.imooc;
import?java.util.Scanner;
public?class?Circle?extends?Shape?{
	
	
	public?void?perimeter()?{
		Scanner?input?=?new?Scanner(System.in);
		System.out.println("請輸入圓形的半徑:");
		float?radius=input.nextFloat();
		System.out.println("圓形的周長為:"+radius*2*3.14);
	}

	public?void?area()?{
		Scanner?input?=?new?Scanner(System.in);
		System.out.println("請輸入圓形的半徑:");
		float?radius=input.nextFloat();
		System.out.println("圓形的面積:"+3.14*radius*radius);?
	}

}
package?com.imooc;

public?class?Initial?{

	public?static?void?main(String[]?args)?{
		Shape?s1=new?Rectangle();
		s1.perimeter();
		s1.area();
		
		
		Shape?s2=new?Circle();
		s2.perimeter();
		s2.area();

	}

}


正在回答

3 回答

可以使用一個方法簡寫直接輸出周長和面積

public abstract class Shape {

? public abstract void get();//求周長和面積

}




import java.util.Scanner;

public class Rectangle extends Shape { ? ??

? ? public void get() {

? ? ? ? Scanner input = new Scanner(System.in);

? ? ? ? System.out.println("請輸入矩形的寬:");

? ? ? ? float width = input.nextFloat();

? ? ? ? System.out.println("請輸入矩形的長:");

? ? ? ? float length=input.nextFloat();

? ? ? ? System.out.println("矩形的周長為:"+2*(width+length));

? ? ? ? System.out.println("矩形的面積為:"+width*length);

?

? ? }

}



import java.util.Scanner;

public class Circle extends Shape {

? ? ?? ?public void get() {

? ? ? ? Scanner input = new Scanner(System.in);

? ? ? ? System.out.println("請輸入圓形的半徑:");

? ? ? ? float radius=input.nextFloat();

? ? ? ? System.out.println("圓形的周長為:"+radius*2*3.14);

? ? ? ? System.out.println("圓形的面積:"+3.14*radius*radius);

? ? }

}



public class Initial {?

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

? ? ? ? Shape s1=new Rectangle();

? ? ? ? s1.get(); ? ? ? ? ? ? ? ? ? ? ??

? ? ? ? Shape s2=new Circle();

? ? ? ? s2.get();?

? ? }

}


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

慕粉3235270 提問者

非常感謝!
2016-06-02 回復(fù) 有任何疑惑可以回復(fù)我~
#2

三個世界0

為什么我在編譯器編譯時 在抽象方法哪里報錯呢??
2017-01-22 回復(fù) 有任何疑惑可以回復(fù)我~

哥們感覺你少了input.close();這個語句,沒有這個語句會報錯在我這

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

為什么我打?public class Rectangle extends Shape ?這個代碼時系統(tǒng)開始報錯啊


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

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學(xué)習(xí)       531100    人
  • 解答問題       6280    個

課程升級!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會Java面向?qū)ο缶幊痰膴W妙

進(jìn)入課程

思考題練習(xí)

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

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

幫助反饋 APP下載

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

公眾號

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