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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么在第一次詢問的時候輸入-1的時候程序正常 而輸入字符卻死循環(huán)?

為什么在第一次詢問的時候輸入-1的時候程序正常 而輸入字符卻死循環(huán)?

package rentbook;import java.util.Scanner;public class text {?? public static Scanner scan=new Scanner(System.in);?? public static book[] bo={??????????? new book("高數(shù)"),??????????? new book("物理"),??????????? new book("語文"),??????????? new book("英語"),??????????? new book("c語言")?? ???? };?? ???? public static void main(String[] args) {??????? // TODO Auto-generated method stub????? while (true){????????? System.out.println("輸入命令:1-按照名稱查找圖書;2-按照序號查找圖書");????????? int inputnum=inputnum1();????????? switch(inputnum){????????? case 1 : System.out.println("按照名稱查找圖書");?????????????????? inputname();?????????????????? break;????????? case 2: System.out.println("按照序號查找圖書");????????????????? System.out.println("請輸入序號");????????????????????? try{????????????????????????? int putnum=inputnum1();????????????????????????? switch(putnum){????????????????????????? case -1: System.out.println("請輸入數(shù)字");break;????????????????????????? default:System.out.println(bo[putnum-1]+"已經(jīng)被您選中了");break;????????????????????????? }????????????????????? }catch(Exception e){????????????????????????? System.out.println("您輸入的數(shù)字過大");????????????????????? }????????????????????? break;????????? case -1 : System.out.println("請輸入數(shù)字");break;????????? default: System.out.println("輸入的數(shù)字不存在");????????? }????? }??? }??? private static void inputname() {??????? // TODO Auto-generated method stub??????? System.out.println("請輸入書名");??????? String input=scan.next();??????????????? for(int i=0;i<bo.length;i++){??????????????? if(input.equals(bo[i].name))??????????????? System.out.println(bo[i].name+"已經(jīng)被您選中了");??????????????? else if(i==bo.length-1){?????????????? ??? ?System.out.println("請輸入正確的書名");?????????????? ??? ?break;??????????????? }??????????????? }??? }??? private static int inputnum1() {??????? // TODO Auto-generated method stub????? ???????? try{?????? ??? ?int a=scan.nextInt();??????????? return a;??????? }catch(Exception e){????????????? return -1;??????? }??? }}
查看完整描述

2 回答

?
sntatas

TA貢獻53條經(jīng)驗 獲得超11個贊

你指的正常是不是程序能夠重新輸入,如果是這樣的話,那應該不管輸入什么都是無限循環(huán)的

問題應該是while(true)導致無限循環(huán),你沒有寫退出條件;switch里的break只退出switch

查看完整回答
反對 回復 2016-11-30
?
Caption_1210

TA貢獻9條經(jīng)驗 獲得超3個贊

目測問題出在while(true)的循環(huán)控制,手機上看有點費眼
查看完整回答
反對 回復 2016-11-30
  • 2 回答
  • 0 關注
  • 1338 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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