package demo1;
import java.util.Scanner;
public class Second {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("请输入要添加的书籍个数:");
int n =sc.nextInt();
String[]library =new String[n];
for(int i=0;i<library.length;i++){
System.out.println("请输入第"+(i+1)+"本书:");
library[i]=sc.next();
}
System.out.println("添加完毕,显示如下:");
for(String name:library){
System.out.println(name);
}
System.out.println("请输入要添加的新书:");
String[] newlib=new String[n*2];
for(int i=0;i<library.length;i++){
newlib[i]=library[i];
}
String book =sc.next();
newlib[n]=book;
library=newlib;
System.out.println("添加完毕,显示如下:");
for(String name:library){
if(name!=null)
System.out.println(name);
}
System.out.println("请输入你要借的书籍名称:");
String borrowBook =sc.next();
boolean bool=false;
int index =0;
for(int i=0;i<library.length;i++){
if(borrowBook.equals(library[i])){
index=i;
//如果包含
bool=true;
}
}
if(bool){
//可以借走,首先拿到这本书的下标
for(int i=index;i<library.length-1;i++){
library[i]=library[i+1];
}
library[n]=null; //null空值
}else{
System.out.println("您要借的书籍已被别人借走~");
}
System.out.println("借阅完毕,显示如下:");
for(String name:library){
if(name!=null)
System.out.println(name);
}
}
}