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

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

java作業(yè)。。

老師布置胡作業(yè)誰做了,借我看看哦

正在回答

5 回答

package library;

import java.util.Scanner;

public class BookScanner {



public static void main(String[] args) {?

?String []bookName={"毛概","光纖通信","星系奇緣","量子力學(xué)","goutou大美","都市妖俠傳","七劍下天山"};

while(true){

System.out.println("歡迎來到工大圖書館查詢系統(tǒng)");

System.out.println("請輸入命令:1-按照名稱查找圖書;2-按照序號查詢圖書");

Scanner input=new Scanner(System.in);

String book;

try{

int a=input.nextInt();

switch(a){

case 1:

System.out.println("請輸入你要查找的圖書名");

book=bookname(bookName);

System.out.println("book:"+"《"+book+"》");

break;

case 2:

System.out.println("請輸入你所查找圖書序號");

book=booknum(bookName);

System.out.println("book:"+"《"+book+"》");

break;

default://其他值的命令均認(rèn)為是錯(cuò)誤命令

System.out.println("命令輸入錯(cuò)誤!");

continue;

}

break;

}catch(Exception e){


}

}

}

public static String bookname(String[] bookName)throws Exception {

System.out.println("輸入圖書名稱:");

Scanner in=new Scanner(System.in);

//獲取輸入的圖書名稱

String name = in.next();

for (int i = 0; i < bookName.length; i++) {

if (name.equals(bookName[i]))

//輸入的名稱與某一圖書名稱匹配,返回該圖書

return bookName[i];

}

//若無匹配,拋出”圖書不存在異?!?/p>

throw new Exception("圖書不存在!");

}

public static String booknum(String[] bookName)throws Exception {

System.out.println("輸入圖書序號:");

Scanner in=new Scanner(System.in);

//獲取輸入的圖書名稱

int b = in.nextInt();

for (int i = 0; i < bookName.length; i++) {

if (b==i)

//輸入的名稱與某一圖書名稱匹配,返回該圖書

return bookName[i];

}

//若無匹配,拋出”圖書不存在異?!?/p>

throw new Exception("圖書不存在!");

}

}



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

珂珂涼 提問者

非常感謝!你的幫助
2016-04-16 回復(fù) 有任何疑惑可以回復(fù)我~

public static void Bookstart()throws Exception{
??????? System.out.println("******書號查詢號請按:1;書名查詢請按:0******");
??????? Scanner sc = new Scanner(System.in);
??????? try {
??????????? int ture = sc.nextInt();
??????????? if(ture==1){
??????????????? System.out.println("******輸入圖書"+"序號******");
??????????????????? BookNum();
??????????? }
??????????? else if(ture==0){
??????????????? System.out.println("******輸入圖書"+"名稱******");?? ?
??????????????????? BookName();
??????????????? }
??????????? else{
??????????????????? throw new Exception("******輸入信息有誤請重新輸入(1/0)******");
??????????????? }
??????? } catch (Exception e) {
??????????? System.out.println("******輸入信息有誤請重新輸入(1/0)******");
??????????? Bookstart();
??????? }
??? }

這段輸入非數(shù)字不會死循環(huán)么?比如說輸入“ssss”

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

package test5;

import java.util.Scanner;

public class Booksystem {

??? static String[] bookname={"高數(shù)","程序編程","大學(xué)英語","操作系統(tǒng)","Java"};

??? public static void main(String[] args) throws Exception {
??????? Bookstart();
??? }
?? ?
??? public static void Bookstart()throws Exception{
??????? System.out.println("******書號查詢號請按:1;書名查詢請按:0******");
??????? Scanner sc = new Scanner(System.in);
??????? try {
??????????? int ture = sc.nextInt();
??????????? if(ture==1){
??????????????? System.out.println("******輸入圖書"+"序號******");
??????????????????? BookNum();
??????????? }
??????????? else if(ture==0){
??????????????? System.out.println("******輸入圖書"+"名稱******");?? ?
??????????????????? BookName();
??????????????? }
??????????? else{
??????????????????? throw new Exception("******輸入信息有誤請重新輸入(1/0)******");
??????????????? }
??????? } catch (Exception e) {
??????????? System.out.println("******輸入信息有誤請重新輸入(1/0)******");
??????????? Bookstart();
??????? }
??? }
?? ?
??? public static void BookNum()throws Exception{
??????? Scanner sc = new Scanner(System.in);
??????? try {?????? ?
??????????? int num = sc.nextInt();
??????????? if(num<=bookname.length&&num>0){
??????????????? System.out.println("******序號"+num+"."+bookname[num-1]+"******");
??????????? }
??????????? else{
??????????????? throw new Exception();
??????????? }
??????? } catch (Exception e) {
??????????? System.out.println("******輸入信息有誤請重新輸入******");
??????????? BookNum();
??????? }
??????? Bookstart();
??? }
?? ?
??? public static void BookName() throws Exception{
??????? Scanner sc = new Scanner(System.in);
??????? try {
??????????? String name = sc.next();
??????????? for(int i = 0;i<bookname.length;i++){
??????????????? if(bookname[i].equals(name)){
?????????????? ??? ?int num=i+1;
??????????????? System.out.println("******序號"+num+"."+bookname[i]+"******");? ?
??????????????? break;
??????????????????? }else{
??????????????????????? throw new Exception();
??????????????????? }?????????????????? ?
??????????? }
????????? ?
??????? } catch (Exception e) {
??????????? System.out.println("******輸入信息有誤請重新輸入******");
??????????? BookName();
??????? }
??????? Bookstart();
??? } ?
}



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

ran1021

哭笑不得...(根據(jù)書名的方法還是不對...
2016-05-11 回復(fù) 有任何疑惑可以回復(fù)我~
#2

ran1021

我已經(jīng)解決了。在 throw new Exception()前加個(gè)條件if(i==bookname.length-1),循環(huán)完了再提示沒找到。
2016-05-11 回復(fù) 有任何疑惑可以回復(fù)我~
#3

森特 回復(fù) ran1021

噢噢!偷懶只試了高數(shù)沒有試其他的書名_(:з」∠)_
2016-05-11 回復(fù) 有任何疑惑可以回復(fù)我~

package tushu;


import java.util.Scanner;


public class book {

? ? int bookNum;

? ? String bookName;

? ??

? ? public book(int bookNum,String bookName){

? ? this.bookNum=bookNum;

? ? this.bookName=bookName;

? ? }

? ??

? ? public ?static void choose1(String ?bookName,book[] book){

? ? int k=0;

? ? for(int i=0;i<book.length;i++){

? ? if(book[i].bookName.equals(bookName)){

? ? System.out.println("book:"+book[i].bookName);

? ? k=1;

? ? }

? ? } ?

? ? if(k!=1){ ?

? ? ? System.out.println("圖書不存在!");

? ? }

? ? }

? ??

? ? public static void choose2(int bookNum,book[] book){

? ? int k=0;

? ? for(int i=0;i<book.length;i++){

? ? if(book[i].bookNum==bookNum){

? ? System.out.println("book:"+book[i].bookName);

? ? k=1;

? ?

? ? }

? ? }

? ? if(k!=1){

? ? ? System.out.println("圖書不存在!");

? ? ?

? ? }

? ?

? ? }

? ??

? ??

public static void main(String[] args) {

// TODO Auto-generated method stub

book[] book=new book[10];

book book0=new book(1,"高數(shù)");

book book1=new book(2,"數(shù)據(jù)結(jié)構(gòu)");

book book2=new book(3,"體育");

book book3=new book(4,"離散數(shù)學(xué)");

book book4=new book(5,"微機(jī)");

book book5=new book(6,"PHP");

book book6=new book(7,"MySql");

book book7=new book(8,"英語");

book book8=new book(9,"計(jì)算機(jī)網(wǎng)絡(luò)");

book book9=new book(10,"C語言");

book[0]=book0;

book[1]=book1;

book[2]=book2;

book[3]=book3;

book[4]=book4;

book[5]=book5;

book[6]=book6;

book[7]=book7;

book[8]=book8;

book[9]=book9;

while(true){

? ? ? ? ? System.out.println("輸入命令:1--按照名稱查找圖書 ? 2--按照序號查找圖書 ");

? ? ? ? ? Scanner i=new Scanner(System.in);

? ? ? ? ? try {

? ? ? ? ? ? ? int choose = i.nextInt();

? ? ? ? ? ? ? if (choose == 1) {

? ? ? ? ? ? ?System.out.println("請輸入要查找圖書的書名:");

? ? ? ? ? ? ?Scanner t=new Scanner(System.in);

? ? ? ? ? ? ?String bookName=t.next();

? ? ? ? ? ? ?choose1(bookName,book);

? ? ? ? ? ? ?

? ? ? ? ? ? ? } else if (choose == 2) {

? ? ? ? ? ? ?System.out.println("請輸入要查找圖書的編號:");

? ? ? ? ? ? ?Scanner t=new Scanner(System.in);

? ? ? ? ? ? ?int bookNum=t.nextInt();

? ? ? ? ? ? ?choose2(bookNum,book);

? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? //重新初始化系統(tǒng)

? ? ? ? ? ? ? ? ? main(null);

? ? ? ? ? ? ? }

? ? ? ? ? } catch (Exception e) {

? ? ? ? ? ? ? System.out.println("輸入類型有誤");

? ? ? ? ? }

? ? ? }

}?

}



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

public class Booksystem {
??? static Scanner sc = new Scanner(System.in);
??? static String[] bookname={"高數(shù)","程序編程","大學(xué)英語","操作系統(tǒng)","Java"};

??? public static void main(String[] args) throws Exception {
??????? System.out.println("******書號查詢號請按:1;書名查詢請按:0:******");
??????? Bookstart();
??? }
?? ?
??? public static void Bookstart()throws Exception{
??????? try {
??????????? int ture = sc.nextInt();
??????????? if(ture==1){
??????????????? System.out.println("******輸入圖書"+"序號******");
??????????????????? BookNum();
??????????? }
??????????? else if(ture==0){
??????????????? System.out.println("******輸入圖書"+"名稱******");?? ?
??????????????????? BookName();
??????????????? }
??????????? else{
??????????????????? throw new Exception("******輸入信息有誤請重新輸入(1/0)******");
??????????????? }
??????? } catch (Exception e) {
??????????? System.out.println("******輸入信息有誤請重新輸入(1/0)******");
??????????? Bookstart();
??????? }
??? }
?? ?
??? public static void BookNum()throws Exception{
??????? try {?????? ?
??????????? int num = sc.nextInt();
??????????? if(num<=bookname.length&&num>0){
??????????????? System.out.println("******序號"+num+"."+bookname[num-1]+"******");
??????????? }
??????????? else{
??????????????? throw new Exception("******輸入信息有誤請重新輸入******");
??????????? }
??????? } catch (Exception e) {
??????????? System.out.println("******輸入信息有誤請重新輸入******");
??????????? BookNum();
??????? }
??? }
?? ?
??? public static void BookName() throws Exception{
??????? try {
??????????? String name = sc.next();
??????????? for(int i = 0;i<bookname.length;i++){
??????????????? if(name == bookname[i]){
??????????????? System.out.println("******序號"+i+1+"."+name+"******");?????????? ?
??????????????????? }else{
??????????????????????? throw new Exception("******輸入信息有誤請重新輸入******");
??????????????????? }?????????????????????????? ?
??????????? }
??????? } catch (Exception e) {
??????????? System.out.println("******輸入信息有誤請重新輸入******");
??????????? BookName();
??????? }
??? } ?
}

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

ran1021

根據(jù)書名的方法好像有錯(cuò)誤,不過我沒找到...
2016-05-06 回復(fù) 有任何疑惑可以回復(fù)我~
#2

森特 回復(fù) ran1021

抱歉啊,居然放上了錯(cuò)誤的代碼。錯(cuò)誤的地方是BookName()中的if語句不能用雙等要用equals方法(而且漏了寫break;),還有其中syso語句中的“"****"+i+1+"****"”,需要再定義變量num=i+1。
2016-05-07 回復(fù) 有任何疑惑可以回復(fù)我~
#3

ran1021 回復(fù) 森特

嗯嗯,我也發(fā)現(xiàn)了,不過還是謝謝。
2016-05-10 回復(fù) 有任何疑惑可以回復(fù)我~
#4

ran1021 回復(fù) 森特

這么改了還是不對哎,可以請教下哪里有問題嗎
2016-05-10 回復(fù) 有任何疑惑可以回復(fù)我~
#5

森特 回復(fù) ran1021

因?yàn)槲矣玫氖浅霈F(xiàn)異常重新執(zhí)行該方法,scanner創(chuàng)建實(shí)例不能用static方法公用,要每個(gè)類定義一個(gè),否則輸入錯(cuò)誤的時(shí)候會造成無法獲取鍵盤輸入而造成死循環(huán)。
2016-05-11 回復(fù) 有任何疑惑可以回復(fù)我~
#6

森特 回復(fù) ran1021

修改之后的代碼放在樓下了_(:з」∠)_
2016-05-11 回復(fù) 有任何疑惑可以回復(fù)我~
查看3條回復(fù)

舉報(bào)

0/150
提交
取消
Java入門第三季
  • 參與學(xué)習(xí)       409775    人
  • 解答問題       4546    個(gè)

Java中你必須懂得常用技能,不容錯(cuò)過的精彩,快來加入吧

進(jìn)入課程

java作業(yè)。。

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

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

幫助反饋 APP下載

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

公眾號

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