java学生姓名录入查询系统

时间:2022-07-21 07:55:19 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。


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