package 上机练习; public class A02class { String names[] = new String[30]; public void showA(String name) { for (int i = 0; i < names.length; i++) { if (names[i] == null) { names[i] = name; break; } } } public void showB() { System.out.println("\t客户列表显示"); for (int i = 0; i < names.length; i++) { if (names[i] != null) { System.out.print(names[i] + "\t"); } } } public boolean showC(String find) { boolean con = false; for (int i = 0; i < names.length; i++) { if (names[i] != null) { if (names[i].equals(find)) { con = true; break; } } } return con; } } package 上机练习; import java.util.Scanner; public class A02 { public static void main(String[] args) { // TODO Auto-generated method stub A02class A02 = new A02class(); Scanner in = new Scanner(System.in); boolean con = true; while (con) { System.out.println("请输入客户的姓名:"); String admin = in.next(); A02.showA(admin); System.out.println("请输入是否继续:(y / n ):"); String choice = in.next(); if (choice.equals("n")) { con = false; break; } } A02.showB(); System.out.println("请输入要查找的客户的姓名:"); String find = in.next(); if (A02.showC(find)) { System.out.println("有"); } else { System.out.println("没有"); } } }
java-第十三章-类的无参方法(一)-查找客户姓名,布布扣,bubuko.com
时间: 2024-10-20 02:40:49