package April; import java.util.Scanner; public class B2 { Scanner input = new Scanner(System.in); String []names=new String[30]; String answer=" "; public void show(String name){ for(int i=0;i<names.length;i++){ if(names[i]==null){ names[i]=name; break; } } } public void show1(){ System.out.println("******学生列表******"); for(int i=0;i<names.length;i++){ if(names[i]!=null){ System.out.print(names[i]+"\t"); } } } public boolean findCustomer(String name){ boolean find = false; int i =0; while(names[i] != null){ if(names[i].equals(name)){ find = true; break; } i++; } return find; } public static void main(String []args){ Scanner input = new Scanner(System.in); B2 xx=new B2(); do{ System.out.print("请输入学生的姓名:"); String name=input.next(); xx.show(name); System.out.println("继续输入吗?(y/n)"); xx.answer =input.next(); } while("y".equals(xx.answer)); xx.show1(); System.out.println(" "); System.out.print("请输入要查找的学生姓名:"); String findname=input.next(); System.out.println("******查找结果******"); if(xx. findCustomer(findname)){ System.out.print("找到了!"); } else{ System.out.print("查无此人!"); } } } 本文来源:https://www.wddqw.com/doc/b1441a9da6c30c2259019ef3.html