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

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

關(guān)于input.next()輸入問(wèn)題

我在MyEclipse里面調(diào)用String s1=input.next();當(dāng)輸入:語(yǔ)文+空格+回車;得到的s1確是:yu語(yǔ)文;不知道怎么回事呀?好像有的時(shí)候能得到正確結(jié)果

正在回答

4 回答

會(huì)不會(huì)是你輸入法問(wèn)題,空格直接把輸入英文也算進(jìn)去了,換個(gè)輸入法試試?

這段代碼雖然很多不規(guī)范的地方,但我在eclipse上運(yùn)行沒(méi)什么問(wèn)題

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

慕函數(shù)1733451 提問(wèn)者

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

慕函數(shù)1733451 提問(wèn)者

這段代碼哪些地方不規(guī)范呢?能不能幫忙指出來(lái)呀!根據(jù)我多次輸入的經(jīng)驗(yàn),我感覺(jué),輸入的時(shí)候注意點(diǎn)擊光標(biāo)換行就不會(huì)有問(wèn)題,如果在“請(qǐng)輸入圖書名稱:”后面直接輸入就有可能出現(xiàn)問(wèn)題,也是奇了怪了
2017-04-12 回復(fù) 有任何疑惑可以回復(fù)我~
package?模擬借書系統(tǒng);?????//包名一般用英文字母小寫,倒寫域名加模塊名加功能名,用"."分割成四級(jí)
import?java.util.Scanner;
import?java.util.InputMismatchException;?
public?class?rendBook?{?????//類名命名遵從大駝峰原則,首字母要大寫,應(yīng)為RendBook
?
????public?static?void?main(String[]?args)?throws?Exception?{????//不是很明白為什么要在這里拋異常
????????//?TODO?Auto-generated?method?stub
???????String[]?book={"語(yǔ)文","數(shù)學(xué)","英語(yǔ)","政治","歷史","地理"};
???????
???????boolean?x=true;??????//見(jiàn)第51行
???????do{
???????????Scanner?input=new?Scanner(System.in);????????//建議把input放到循環(huán)外面,并在循環(huán)結(jié)束后關(guān)閉input,input.closed()
???????????System.out.println("請(qǐng)輸入命令:1-按照名稱查找圖書;2-按照序號(hào)查找圖書");
???????????try{
???????????????int?order=input.nextInt();?
???????????????if(order!=1&&order!=2)
???????????????????throw?new?Exception("請(qǐng)按提示輸入數(shù)字");?????//括號(hào)內(nèi)不必寫入內(nèi)容
???????????????if(order==1){
???????????????????System.out.println("請(qǐng)輸入圖書名稱:");
???????????????????String?s1=input.next();
???????????????????System.out.println(s1);
???????????????????for(int?i=0;i<book.length;i++){
???????????????????????if(book[i].equals(s1)){
???????????????????????????System.out.println("有這本書:"+book[i]);
???????????????????????????break;
???????????????????????}
???????????????????????if(i==book.length-1)
???????????????????????????System.out.println("圖書不存在!");
???????????????????}
????????????????????
???????????????}
???????????????else{
???????????????????System.out.println("請(qǐng)輸入圖書序號(hào):");
???????????????????int?num=input.nextInt();
???????????????????if(num>book.length){
???????????????????????System.out.println("圖書不存在!");????
???????????????????}
???????????????????else{
???????????????????????System.out.println("有這本書:"+book[num-1]);
???????????????????}
???????????????}
?????????????break;??
???????????}
???????????catch(InputMismatchException?e){
????????????System.out.println("輸入有誤,請(qǐng)重新輸入!");??????
????????????//input.next();
???????????}?
???????????catch(Exception?e){
???????????????System.out.println("請(qǐng)按提示輸入數(shù)字,謝謝合作!");
???????????????}
???????}while(x);???????//while(true)就行,第10行可以省略
??????????
???????}
?
}
//還有一些空格縮進(jìn)問(wèn)題,寫完最好ctrl+shift+f格式化一下

在eclipse控制臺(tái)輸入一般換行輸入

https://yq.aliyun.com/articles/69327

這是阿里的編程規(guī)范,你可以下載參考下

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

慕函數(shù)1733451 提問(wèn)者

這么多注釋呀??!呵呵
2017-04-13 回復(fù) 有任何疑惑可以回復(fù)我~


package?模擬借書系統(tǒng);
import?java.util.Scanner;
import?java.util.InputMismatchException;?
public?class?rendBook?{

	public?static?void?main(String[]?args)?throws?Exception?{
		//?TODO?Auto-generated?method?stub
???????String[]?book={"語(yǔ)文","數(shù)學(xué)","英語(yǔ)","政治","歷史","地理"};
??????
???????boolean?x=true;
???????do{
????	???Scanner?input=new?Scanner(System.in);
????	???System.out.println("請(qǐng)輸入命令:1-按照名稱查找圖書;2-按照序號(hào)查找圖書");
????	???try{
????		???int?order=input.nextInt();?
????		???if(order!=1&&order!=2)
????			???throw?new?Exception("請(qǐng)按提示輸入數(shù)字");
????		???if(order==1){
????			???System.out.println("請(qǐng)輸入圖書名稱:");
????			???String?s1=input.next();
????			???System.out.println(s1);
????			???for(int?i=0;i<book.length;i++){
????				???if(book[i].equals(s1)){
????					???System.out.println("有這本書:"+book[i]);
????					???break;
????				???}	
????				???if(i==book.length-1)
????????				???System.out.println("圖書不存在!");
????			???}
????			???
????		???}
????		???else{
????			???System.out.println("請(qǐng)輸入圖書序號(hào):");
????			???int?num=input.nextInt();
????			???if(num>book.length){
????				???System.out.println("圖書不存在!");	???
????			???}
????			???else{
????				???System.out.println("有這本書:"+book[num-1]);
????			???}
????		???}
????		?break;??
????	???}
????	???catch(InputMismatchException?e){
????		System.out.println("輸入有誤,請(qǐng)重新輸入!");
????		//input.next();
????	???}?
????	???catch(Exception?e){
????		???System.out.println("請(qǐng)按提示輸入數(shù)字,謝謝合作!");
????		???}
???????}while(x);
?????????
???????}

}


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

代碼截圖

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

慕函數(shù)1733451 提問(wèn)者

貼在下面了??!
2017-03-25 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

關(guān)于input.next()輸入問(wèn)題

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

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

幫助反饋 APP下載

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

公眾號(hào)

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