為什么在輸入圖書(shū)名稱(chēng)之后不會(huì)運(yùn)行下面的輸出Book的語(yǔ)句呢
package com.BorrowBooks;
import java.util.Scanner;
public class book {
??public static void main(String[] args) {
???for(;;){
???System.out.println("歡迎使用借書(shū)系統(tǒng)");
???System.out.println("輸入命令:1.按名稱(chēng)查找圖書(shū)?? 2.按序號(hào)查找圖書(shū)");
???Scanner in=new Scanner(System.in);
???int choice = 3;
???int i = 0;
???int j = 0;
???String[] Book = {"高數(shù)","線代","概率論與數(shù)理統(tǒng)計(jì)","大學(xué)英語(yǔ)","數(shù)據(jù)庫(kù)","操作系統(tǒng)","java面向?qū)ο?};
???try{
????choice = in.nextInt();
???}catch(Exception e){
????System.out.println("命令輸入錯(cuò)誤,請(qǐng)根據(jù)提示輸入整形的數(shù)字");
????continue;
???}
???if(choice == 1){
????System.out.println("請(qǐng)輸入你要借的書(shū)的名稱(chēng)");
????try{
?????for(i=0;i<Book.length;i++){
??????if(Book[i]==in.nextLine()){
???????System.out.println("Book:"+Book[i]);
???????continue;?
?????}
????}catch(Exception e){
?????System.out.println("圖書(shū)不存在");
?????continue;
????}
???}else if(choice == 2){
????System.out.println("請(qǐng)輸入你要借的書(shū)的序號(hào)");
????try{
?????for(j=0;j<Book.length;j++){
??????if(j==in.nextInt()){
???????System.out.println("Book:"+Book[i]);
???????continue;
??????????????? }
????}catch(Exception e){
?????System.out.println("圖書(shū)不存在");
?????continue;
????}
???}else {
????System.out.println("你的選擇錯(cuò)誤");
???}
??}
??}
?}
2016-08-05
Exception無(wú)法轉(zhuǎn)換為T(mén)hrowable
2016-08-05
你這寫(xiě)的 問(wèn)題太多了
2016-08-02
是我傻了哦,這樣寫(xiě)就好了
package com.BorrowBooks;
//import java.awt.print.Book;
import java.util.Scanner;
public class book {
??@SuppressWarnings("resource")
??public static void main(String[] args){
???for(;;){
???System.out.println("歡迎使用借書(shū)系統(tǒng)");
???System.out.println("輸入命令:1.按名稱(chēng)查找圖書(shū)?? 2.按序號(hào)查找圖書(shū)");
???Scanner in=new Scanner(System.in);
???int choice = 3;
//???int i= 0;
//???int j = 0;
//???String[] Book = {"高數(shù)","線代","概率論與數(shù)理統(tǒng)計(jì)","大學(xué)英語(yǔ)","數(shù)據(jù)庫(kù)","操作系統(tǒng)","java面向?qū)ο?};
???try{
????choice = in.nextInt();
???}catch(Exception e){
????System.out.println("命令輸入錯(cuò)誤,請(qǐng)根據(jù)提示輸入整形的數(shù)字");
????continue;
???}
???if(choice == 1){
//????System.out.println("請(qǐng)輸入你要借的書(shū)的名稱(chēng)");
//????for(i=0;i<Book.length;i++){
//????try{
//?????? ?in.nextLine().equals(Book[i]);
//???????System.out.println("Book:"+Book[i]);
//???????break;
//????}catch(Exception e){
//?????System.out.println("圖書(shū)不存在");
//?????continue;
//????}
//????}
//???System.out.println("Book:"+Book[i]);
????book Mc = new book();
????Mc.find1();
???}else if(choice == 2){
//????System.out.println("請(qǐng)輸入你要借的書(shū)的序號(hào)");
//????for(j=0;j<Book.length;j++){
//????try{
//?????? j=in.nextInt();
//?????System.out.println("Book:"+Book[j]);
//?????break;
//????}catch(Exception e){
//?????System.out.println("圖書(shū)不存在");
//?????continue;
//????}
//????}
//????System.out.println("Book:"+Book[j]);
????book Xh = new book();
????Xh.find2();
???}else {
????System.out.println("你的選擇錯(cuò)誤");
???}
??}
??}
??@SuppressWarnings("resource")
??public void find1(){
???int i = 0;
???String[] Book = {"高數(shù)","線代","概率論與數(shù)理統(tǒng)計(jì)","大學(xué)英語(yǔ)","數(shù)據(jù)庫(kù)","操作系統(tǒng)","java面向?qū)ο?};
???System.out.println("請(qǐng)輸入你要借的書(shū)的名稱(chēng)");
???Scanner in=new Scanner(System.in);
???String H = in.next();
???for(i=0;i<Book.length;i++){
???try{
????? ?H.equals(Book[i]);
??????System.out.println("Book:"+H);
??????break;
???}catch(Exception e){
????System.out.println("圖書(shū)不存在");
????continue;
???}
???}
??}
??@SuppressWarnings("resource")
??public void find2(){
???int j = 0;
???String[] Book = {"高數(shù)","線代","概率論與數(shù)理統(tǒng)計(jì)","大學(xué)英語(yǔ)","數(shù)據(jù)庫(kù)","操作系統(tǒng)","java面向?qū)ο?};
???System.out.println("請(qǐng)輸入你要借的書(shū)的序號(hào)");
???Scanner in=new Scanner(System.in);
???for(j=0;j<Book.length;j++){
???try{
????? j=in.nextInt();
????System.out.println("Book:"+Book[j]);
????break;
???}catch(Exception e){
????System.out.println("圖書(shū)不存在");
????continue;
???}
???}
??}
?}
2016-08-01
根據(jù)你的代碼你必須輸入Book.length次才執(zhí)行輸出語(yǔ)句,而且你的判斷語(yǔ)句后面沒(méi)有執(zhí)行語(yǔ)句?if完然后干嘛?