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

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

請(qǐng)問哪里錯(cuò)了?

public?class?Show?{
????public?static?void?main(String[]?args)?{
		Shape?shape1?=?new?Circle();
		Shape?shape2?=?new?Rectangle();
		shape1.area();
		shape1.grith();
		shape2.area();
		shape2.grith();
	}

}

public?abstract?class?Shape?{
	
	public?abstract?void?area();
	public?abstract?void?grith();

}
public?class?Circle?extends?Shape?{
????double??r?;
	static?double?pi?=?3.14;
	public?void?area()?{
		System.out.print("輸入一個(gè)半徑:");
		Scanner?scanner?=?new?Scanner(System.in);
		int?r?=?scanner.nextInt();
		this.r?=?r;
		scanner.close();
		
		double?area?=?pi*r*r;
		System.out.println("the?circle's?area?is?"?+?area);
	}

	public?void?grith()?{
	????double?grith?=?2*pi*r;
????????System.out.println("the?grith?is?"?+?grith);
	}

}
public?class?Rectangle?extends?Shape{

	static?double?length?=?0;
	static?double?width?=?0;
	public?void?area()?{
		System.out.print("輸入長(zhǎng)和寬:");
		Scanner?scanner?=?new?Scanner(System.in);
		double?length?=?scanner.nextDouble();
		double?width?=?scanner.nextDouble();
		scanner.close();
		
		double?area?=?length*width;
		System.out.println("the?rectangle's?area?is?"?+?area);
	}

	public?void?grith()?{
		//?TODO?Auto-generated?method?stub
	
	????double?grith?=?2*length*width;
????????System.out.println("the?rectangle's?grith?is?"?+?grith);
	}

}


正在回答

2 回答

public?void?close()關(guān)閉此掃描器。?
如果此掃描器尚未關(guān)閉,并且其底層?readable?也實(shí)現(xiàn)?Closeable?接口,則該?readable?的?close?方法將被調(diào)用。
System.in是InputStream的對(duì)象,并且關(guān)掉之后不能再打開

Java?是順序執(zhí)行的?你執(zhí)行到.close()?后就代表?你關(guān)閉了?流,你再去調(diào)用已經(jīng)被你關(guān)閉的流?顯然是不現(xiàn)實(shí)的
我的建議是?你做幾個(gè)方法里面包含輸入流,然后在main里面調(diào)用就可以了

如果非要用System.in,那么在沒有全部讀取完之前不要關(guān)閉Scanner


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

qq_上帝的智齒_0 提問者

非常感謝!
2017-04-02 回復(fù) 有任何疑惑可以回復(fù)我~

使用場(chǎng)景有很多,我在就跟你說一種,適當(dāng)使用內(nèi)部類,使得代碼更加靈活和富有擴(kuò)展性。其他場(chǎng)景,隨著你深入的學(xué)習(xí)之后就會(huì)接觸到對(duì)嚴(yán)謹(jǐn)。。。

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

舉報(bào)

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

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

進(jìn)入課程

請(qǐng)問哪里錯(cuò)了?

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

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

幫助反饋 APP下載

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

公眾號(hào)

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