我的程序是輸入一個子字符串並返回基於search.i的所有書籍,我想再次要求用戶再次從相同的記錄中搜索。代碼不問對於第二time.Kindly用戶輸入幫助在while循環再次開始後不要求輸入
boolean runnable=true;
while(runnable)
{
System.out.println("\n\nInput Books you wish for search");
String search;
search=br.nextLine();
System.out.println("\n\nBooks by your search");
for(int i=0;i<noOfrecords;i++)
{
if(books[i].toLowerCase().contains(search.toLowerCase()))
{
System.out.println(books[i]);
}
}
System.out.println("\n\nMore Books");
for(int i=0;i<noOfrecords;i++)
{
if(!(books[i].toLowerCase().contains(search.toLowerCase())))
{
System.out.println(books[i]);
}
}
System.out.println("do you wish to search again from the same records?? (y/n)");
char searchagain=br.next().charAt(0);
if(searchagain!='y')
{
runnable=false;
}
else if(searchagain=='y')
{
runnable=true;
}
}
做一件事改變搜索字符串並輸入是或否......在搜索後再次打印搜索if(searchagain.equalsIgnorecCase。(「yes」)) \t { \t runnable = true; \t}來驗證 – Naren