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("沒有"); } } }