本帖最後由 黃博鴻 於 2012-11-24 17:07 編輯
- import java.io.Console;
- public class ch42
- {
- public static void main(String args[])
- {
- Console console=System.console();
- String name;
- System.out.println("***明久的電話簿***");
- System.out.println("1.請輸入'all'以顯示完整電話簿\n2.輸入名字以顯示目標電話\n3.輸入'end'以結束程式");
- System.out.print("請輸入: ");
- name=console.readLine();
- String tel[][]={{"板本雄二","0985-326124"},{"土屋康太","0987-517640"}
- ,{"木下秀吉","0956-784356"},{"島田美波","0934-521345"},
- {"姬路瑞希","0965-521521"},{"工藤愛子","0956-599599"}};
- if(name.equals("all")==true)
- {
- System.out.println("編號\t姓名\t\t電話號碼");
- System.out.println("=====================================");
- for(int i=0; i<=5; i++)
- {
- System.out.print((i+1)+"\t");
- for(int j=0; j<=1; j++)
- {
- System.out.print(tel[i][j]+"\t");
- }
- System.out.println();
- }
- } else
- {
- for(int i=0; i<=5; i++)
- {
- if(name.equals(tel[i][0])==true)
- {
- System.out.println("此人的電話號碼"+tel[i][1]);
- break;
- }else
- {
- if(name.equals(tel[0][0])==false && name.equals(tel[1][0])==false
- && name.equals(tel[2][0])==false && name.equals(tel[3][0])==false
- && name.equals(tel[4][0])==false && name.equals(tel[5][0])==false)
- {
- System.out.println("輸入錯誤");
- break;
- }
- continue;
- }
- }
- }
- }
- }
複製代碼 |