課程
/后端開發(fā)
/Java
/Java入門第三季
老師布置胡作業(yè)誰做了,借我看看哦
2016-04-15
源自:Java入門第三季 1-9
正在回答
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+"》");
default://其他值的命令均認(rèn)為是錯(cuò)誤命令
System.out.println("命令輸入錯(cuò)誤!");
continue;
}
}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("輸入圖書序號:");
int b = in.nextInt();
if (b==i)
珂珂涼 提問者
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”
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();??? } ?}
ran1021
森特 回復(fù) ran1021
package tushu;
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){
? ? if(book[i].bookNum==bookNum){
? ?
? ? if(k!=1){
? ? ?
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;
? ? ? ? ? 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("請輸入要查找圖書的編號:");
? ? ? ? ? ? ?int bookNum=t.nextInt();
? ? ? ? ? ? ?choose2(bookNum,book);
? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? //重新初始化系統(tǒng)
? ? ? ? ? ? ? ? ? main(null);
? ? ? ? ? ? ? }
? ? ? ? ? } catch (Exception e) {
? ? ? ? ? ? ? System.out.println("輸入類型有誤");
? ? ? ? ? }
? ? ? }
}?
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();??????? }??? } ?}
ran1021 回復(fù) 森特
舉報(bào)
Java中你必須懂得常用技能,不容錯(cuò)過的精彩,快來加入吧
3 回答作業(yè)作業(yè)!
1 回答作業(yè)作業(yè)!
3 回答java入門第三季 最后的作業(yè),求指導(dǎo)
2 回答作業(yè)作業(yè)來了
2 回答交作業(yè)交作業(yè)
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-04-16
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("圖書不存在!");
}
}
2016-05-23
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”
2016-05-11
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();
??? } ?
}
2016-04-17
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("輸入類型有誤");
? ? ? ? ? }
? ? ? }
}?
}
2016-04-16
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();
??????? }
??? } ?
}