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

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

finally不執(zhí)行。

http://img1.sycdn.imooc.com//57a2b91e0001807d06540192.jpg這個(gè)finally只執(zhí)行了 第一個(gè)號(hào)System.out.println("是否繼續(xù)查找:Y是,N否");

之后不能進(jìn)行用戶輸入?

問下各位怎么解決啊

正在回答

3 回答

沒見過在finally里這么干的,finally一般是用來釋放資源的,不會(huì)在里面做一些等待用戶輸入的操作。

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

ivwv 提問者

問下 之前說的釋放資源的意思我一直沒搞懂 是用來關(guān)閉程序之類的操作的嗎?
2016-08-06 回復(fù) 有任何疑惑可以回復(fù)我~
#2

ivwv 提問者 回復(fù) ivwv 提問者

剛才問了問 就是釋放內(nèi)存。。。。
2016-08-06 回復(fù) 有任何疑惑可以回復(fù)我~
#3

ziom 回復(fù) ivwv 提問者

你想說什么
2016-08-06 回復(fù) 有任何疑惑可以回復(fù)我~
#4

ivwv 提問者 回復(fù) ziom

沒什么想問的了 謝謝
2016-08-09 回復(fù) 有任何疑惑可以回復(fù)我~
查看1條回復(fù)
import?java.util.Scanner;

public?class?Test1?extends?Test2?{
		book?b?=?new?book();
	
	public?static?void?main(String[]?args)?{
		//?TODO?Auto-generated?method?stub
		Test1?t?=new?Test1();
		t.show();
	
	}
		//用show方法通過if判斷調(diào)用show1和show2方法?
		public?void?show(){
			Scanner?sc?=?new?Scanner(System.in);
			try?{
				b.books();
				int?i?=?sc.nextInt();
				if?(i==1){
					super.show1();
				}else?if(i?==?2){
					super.show2();
				}else{
					b.sys3();
				}
			}catch(Exception?e){
				b.sys3();
			}finally{			//通過finally塊來判斷用戶接下來的操作
				System.out.println("是否繼續(xù)查找:Y是,N否");
				Scanner?ccc?=new?Scanner(System.in);????
	//關(guān)于之前問的finally塊執(zhí)行不完全的,解決辦法:可以通過在外面加一個(gè)while循環(huán)?就會(huì)繼續(xù)執(zhí)行
	//也可以新new一個(gè)Scanner?然后也會(huì)繼續(xù)執(zhí)行
	//目前這個(gè)是之前在Tese1類里new一個(gè)Scanner,所以要是只通過在finally塊里新new一個(gè)Scanner的話
	//會(huì)把之前的sc.next()略過,繼續(xù)執(zhí)行到下一個(gè)ccc.nextLine()
	//不過用用while循環(huán)里面在新new一個(gè)Scanner?和在show方法里也新new一個(gè)Scanner?就可以解決了
	//目前我只知道這么多?沒說到的希望大神們能繼續(xù)說全?謝謝啦??!
	
				while(true){	??????????????????????????	
					String?yes?=?ccc.nextLine();
				if?(yes.equals("y")||yes.equals("Y")){
					show();
					break;
				}else?if?(yes.equalsIgnoreCase("N")||yes.equals("n")){
					System.out.println("感謝使用!");
					break;
				
				}else?{
				b.sys3();
					continue;
				}
				}
			}
		}

}
import?java.util.Scanner;
	//用show1方法來儲(chǔ)存根據(jù)編號(hào)搜索圖書的程序
public?class?Test2?extends?book{
	Scanner?sc?=?new?Scanner(System.in);
	public?void?show1(){??
		super.sys2();
			try{
				int?number?=?sc.nextInt();
				
				if(number?==1){
					super.gs();
					
				}else?if?(number?==?2){
					super.yy();
					
				}
			}catch(Exception?e){
				super.bcz();
				
			}?
		}
	//用show2方法來儲(chǔ)存用圖書名搜索的圖書程序
	public?void?show2(){
		super.sys1();
		try?{
			String?title?=?sc.nextLine();
			if?(title.equals("高數(shù)")){
				super.gs();
			}else?if?(title.equalsIgnoreCase("論語")){
				super.ly();
			}else{
				super.bcz();
			}
		}catch(Exception?e){
			super.sys3();
		}
	}
	}
package?tryCatchfinally;
	//用來儲(chǔ)存所用到的方法
public??class?book?{
	??
	public?void?books(){
		System.out.println("輸入命令:1-按照名稱查詢圖書;2-按照序號(hào)查詢圖書");
	}
	public?void?sys1(){
		System.out.println("請(qǐng)輸入圖書名字");
	}
	public?void?sys2(){
		System.out.println("請(qǐng)輸入圖書編號(hào)");
	}
	public?void?sys3(){
		System.out.println("請(qǐng)按提示輸入,請(qǐng)重新輸入");
		}
	public?void?ly(){
		System.out.println("論語");
	}
	public?void?yy(){
		System.out.println("音樂");
	}
	public?void?gs(){
		System.out.println("高數(shù)");
	}
	public?void?bcz(){
		System.out.println("圖書不存在");
	}
}

問題都在注釋里寫了?

目前最終的代碼


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

http://img1.sycdn.imooc.com//57a2cdbb0001eb2b08450298.jpg目前在if外面套了一個(gè)while循環(huán)就可以繼續(xù)執(zhí)行了 但是不清楚原理 有大神能給說說嗎

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

舉報(bào)

0/150
提交
取消

finally不執(zhí)行。

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

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

幫助反饋 APP下載

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

公眾號(hào)

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