亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么在輸入圖書名稱之后不會運行下面的輸出Book的語句呢

package com.BorrowBooks;


import java.util.Scanner;


public class book {
??public static void main(String[] args) {
???for(;;){
???System.out.println("歡迎使用借書系統");
???System.out.println("輸入命令:1.按名稱查找圖書?? 2.按序號查找圖書");
???Scanner in=new Scanner(System.in);
???int choice = 3;
???int i = 0;
???int j = 0;
???String[] Book = {"高數","線代","概率論與數理統計","大學英語","數據庫","操作系統","java面向對象"};
???try{
????choice = in.nextInt();
???}catch(Exception e){
????System.out.println("命令輸入錯誤,請根據提示輸入整形的數字");
????continue;
???}
???if(choice == 1){
????System.out.println("請輸入你要借的書的名稱");
????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("圖書不存在");
?????continue;
????}
???}else if(choice == 2){
????System.out.println("請輸入你要借的書的序號");
????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("圖書不存在");
?????continue;
????}
???}else {
????System.out.println("你的選擇錯誤");
???}
??}
??}
?}


正在回答

4 回答

Exception無法轉換為Throwable

0 回復 有任何疑惑可以回復我~

你這寫的 問題太多了

0 回復 有任何疑惑可以回復我~

是我傻了哦,這樣寫就好了

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("歡迎使用借書系統");
???System.out.println("輸入命令:1.按名稱查找圖書?? 2.按序號查找圖書");
???Scanner in=new Scanner(System.in);
???int choice = 3;
//???int i= 0;
//???int j = 0;
//???String[] Book = {"高數","線代","概率論與數理統計","大學英語","數據庫","操作系統","java面向對象"};
???try{
????choice = in.nextInt();
???}catch(Exception e){
????System.out.println("命令輸入錯誤,請根據提示輸入整形的數字");
????continue;
???}
???if(choice == 1){
//????System.out.println("請輸入你要借的書的名稱");
//????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("圖書不存在");
//?????continue;
//????}
//????}
//???System.out.println("Book:"+Book[i]);
????book Mc = new book();
????Mc.find1();
???}else if(choice == 2){
//????System.out.println("請輸入你要借的書的序號");
//????for(j=0;j<Book.length;j++){
//????try{
//?????? j=in.nextInt();
//?????System.out.println("Book:"+Book[j]);
//?????break;
//????}catch(Exception e){
//?????System.out.println("圖書不存在");
//?????continue;
//????}
//????}
//????System.out.println("Book:"+Book[j]);
????book Xh = new book();
????Xh.find2();
???}else {
????System.out.println("你的選擇錯誤");
???}
??}
??}
??@SuppressWarnings("resource")
??public void find1(){
???int i = 0;
???String[] Book = {"高數","線代","概率論與數理統計","大學英語","數據庫","操作系統","java面向對象"};
???System.out.println("請輸入你要借的書的名稱");
???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("圖書不存在");
????continue;
???}
???}
??}
??@SuppressWarnings("resource")
??public void find2(){
???int j = 0;
???String[] Book = {"高數","線代","概率論與數理統計","大學英語","數據庫","操作系統","java面向對象"};
???System.out.println("請輸入你要借的書的序號");
???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("圖書不存在");
????continue;
???}
???}
??}
?}


1 回復 有任何疑惑可以回復我~

根據你的代碼你必須輸入Book.length次才執行輸出語句,而且你的判斷語句后面沒有執行語句?if完然后干嘛?

1 回復 有任何疑惑可以回復我~
#1

JJJava

還有字符串判斷要用equals()
2016-08-01 回復 有任何疑惑可以回復我~
#2

JJJava

還有字符串判斷要用equals()
2016-08-01 回復 有任何疑惑可以回復我~
#3

Destiny命運 提問者

不要輸入Book.length次啊,我只是判斷我從鍵盤輸入的那個圖書的名稱和我數組中的是否相同而已,
2016-08-02 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么在輸入圖書名稱之后不會運行下面的輸出Book的語句呢

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號