package 上機練習; public class A01class { String names [] = new String [30]; public void show1(String name){ for (int i = 0; i < names.length; i++) { if(names[i]==null){ names[i]=name; break; } } } public void show2(){ System.out.println("******************************"); System.out.println("\t客戶姓名列表"); System.out.println("******************************"); for (int i = 0; i < names.length; i++) { if(names[i]!=null){ System.out.print(names[i]+" "); } } } } package 上機練習; import java.util.Scanner; public class A01 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner (System.in); A01class A01 = new A01class(); boolean con=true; while(con){ System.out.println("請輸入客戶姓名:"); String admin=in.next(); A01.show1(admin); System.out.println("繼續嗎?(Y /N ):"); String choice=in.next(); if(choice.equals("n")){ con=false; A01.show2(); } } } }