標題:
電話簿 (三)
[打印本頁]
作者:
tonyh
時間:
2012-11-24 17:07
標題:
電話簿 (三)
本帖最後由 tonyh 於 2012-11-24 17:32 編輯
複習 continue 與 break 語法, 改寫我們剛剛寫的程式,
讓使用者可反覆地查詢, 並在輸入'end' 後結束程式.
import java.io.Console;
public class ch43
{
public static void main(String args[])
{
String name;
String tel[][]={{"大雄","0980-454666"},
{"技安","0911-333898"},
{"宜靜","0922-999579"},
{"阿福","0938-234567"},
{"小叮噹","0911-864356"}};
Console console=System.console();
System.out.println("***小米的電話簿***");
while(true)
{
int sum=0;
System.out.println("\n1.輸入'all'顯示完整電話簿\n2.輸入姓名查詢目標對象的電話\n3.輸入'end'結束程式");
System.out.print("請在此輸入: ");
name=console.readLine();
if(name.equals("all")==true)
{
System.out.println("編號\t姓名\t電話");
System.out.println("============================");
for(int i=0; i<=4; i++)
{
System.out.print((i+1)+"\t");
for(int j=0; j<=1;j++)
{
System.out.print(tel[i][j]+"\t");
}
System.out.println();
}
continue;
}else if(name.equals("end")==true)
{
break;
}
else
{
for(int i=0; i<=4; i++)
{
if(name.equals(tel[i][0])==true)
{
System.out.println(tel[i][0]+"的電話是"+tel[i][1]);
sum++;
}
}
if(sum==0)
{
System.out.println("查無此人!");
}
continue;
}
}
}
}
複製代碼
作者:
黃博鴻
時間:
2012-11-24 17:34
import java.io.Console;
public class ch43
{
public static void main(String args[])
{
Console console=System.console();
String name;
System.out.println("***明久的電話簿***");
while(true)
{
System.out.println("\n1.請輸入'all'以顯示完整電話簿\n2.輸入名字以顯示目標電話\n3.輸入'end'以結束程式");
int sum=0;
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();
}
continue;
}else if(name.equals("end")==true)
{
break;
}
else
{
for(int i=0; i<=5; i++)
{
if(name.equals(tel[i][0])==true)
{
System.out.println(tel[i][0]+"的電話號碼"+tel[i][1]);
sum++;
continue;
}
}
if(sum==0)
{
System.out.println("輸入錯誤");
continue;
}
}
}
}
}
複製代碼
作者:
t2364705
時間:
2012-11-24 17:38
import java.io.Console;
public class ch42
{
public static void main(String args[])
{
String name;
String tel[][]={{"大雄","0980-564561"},
{"小夫","0911-333898"},
{"靜香","0922-999579"},
{"胖虎","0938-244567"},
{"小叮噹","0947-864356"}};
Console console=System.console();
System.out.println("***小米的電話簿***");
while(true)
{
int sum=0;
System.out.println("\n1.輸入'all'顯示完整電話簿\n2.輸入姓名查詢目標對象的電話\n3.輸入'end'結束程式");
System.out.print("請在此輸入: ");
name=console.readLine();
if(name.equals("all")==true)
{
System.out.println("編號\t姓名\t電話");
System.out.println("============================");
for(int i=0; i<=4; i++)
{
System.out.print((i+1)+"\t");
for(int j=0; j<=1;j++)
{
System.out.print(tel[i][j]+"\t");
}
System.out.println();
}
continue;
}else if(name.equals("end")==true)
{
break;
}
else
{
for(int i=0; i<=4; i++)
{
if(name.equals(tel[i][0])==true)
{
System.out.println(tel[i][0]+"的電話是"+tel[i][1]);
sum++;
}
}
if(sum==0)
{
System.out.println("查無此人!");
}
continue;
}
}
}
}
複製代碼
作者:
尤泓鈞
時間:
2012-11-24 17:41
import java.io.Console;
public class ch43
{
public static void main(String args[])
{
String name;
String tel[][]={{"大雄","0980-454666"},
{"技安","0911-333898"},
{"宜靜","0922-999579"},
{"阿福","0938-234567"},
{"小叮噹","0911-864356"}};
Console console=System.console();
System.out.println("***小米的電話簿***");
while(true)
{
int sum=0;
System.out.println("\n1.輸入'all'顯示完整電話簿\n2.輸入姓名查詢目標對象的電話\n3.輸入'end'結束程式");
System.out.print("請在此輸入: ");
name=console.readLine();
if(name.equals("all")==true)
{
System.out.println("編號\t姓名\t電話");
System.out.println("============================");
for(int i=0; i<=4; i++)
{
System.out.print((i+1)+"\t");
for(int j=0; j<=1;j++)
{
System.out.print(tel[i][j]+"\t");
}
System.out.println();
}
continue;
}else if(name.equals("end")==true)
{
break;
}
else
{
for(int i=0; i<=4; i++)
{
if(name.equals(tel[i][0])==true)
{
System.out.println(tel[i][0]+"的電話是"+tel[i][1]);
sum++;
}
}
if(sum==0)
{
System.out.println("查無此人!");
}
continue;
}
}
}
}
複製代碼
作者:
lon
時間:
2012-11-24 17:42
import java.io.*;
public class phone {
public static void main(String[] args) {
String tel[][]={{"甲","0912-123456"},
{"乙","0923-234567"},
{"丙","0934-345678"},
{"丁","0945-456789"},
{"戊","0956-567891"}};
Console console=System.console();
while(true){
int sum=0;
System.out.println("***小米的電話簿***");
System.out.println("1.輸入all顯示完整電話簿\n2.輸入姓名查詢目標對象的電話\n3.輸入end結束程式");
String name;
name=console.readLine();
if(name.equals("all")==true){
for(int i=0;i<5;i++){
System.out.print((i+1)+"\t");
for(int j=0;j<2;j++){
System.out.println(tel[i][j]);
}
}
continue;
}else if(name.equals("end")==true){
break;
}else
{
for(int i=0;i<5;i++){
if(name.equals(tel[i][0])==true){
System.out.println(tel[i][0]+"\t"+tel[i][1]);
sum++;
}
}
if(sum==0){
System.out.println("查無此人");
continue;
}
}
}
}
}
複製代碼
作者:
劉漢文
時間:
2012-12-8 15:18
import java.io.Console;
public class ch43
{
public static void main(String args[])
{
String name;
String tel[][]={{"大雄","0980-454666"},
{"技安","0911-333898"},
{"宜靜","0922-999579"},
{"阿福","0938-234567"},
{"小叮噹","0911-864356"}};
Console console=System.console();
System.out.println("***小米的電話簿***");
while(true)
{
int sum=0;
System.out.println("\n1.輸入'all'顯示完整電話簿\n2.輸入姓名查詢目標對象的電話\n3.輸入'end'結束程式");
System.out.print("請在此輸入: ");
name=console.readLine();
if(name.equals("all")==true)
{
System.out.println("編號\t姓名\t電話");
System.out.println("============================");
for(int i=0; i<=4; i++)
{
System.out.print((i+1)+"\t");
for(int j=0; j<=1;j++)
{
System.out.print(tel[i][j]+"\t");
}
System.out.println();
}
continue;
}else if(name.equals("end")==true)
{
break;
}
else
{
for(int i=0; i<=4; i++)
{
if(name.equals(tel[i][0])==true)
{
System.out.println(tel[i][0]+"的電話是"+tel[i][1]);
sum++;
}
}
if(sum==0)
{
System.out.println("查無此人!");
}
continue;
}
}
}
}
複製代碼
作者:
t3742238
時間:
2012-12-8 15:18
import java.io.Console;
public class ch43
{
public static void main(String args[])
{
String name;
String tel[][]={{"大雄","0980-454666"},
{"技安","0911-333898"},
{"宜靜","0922-999579"},
{"阿福","0938-234567"},
{"小叮噹","0911-864356"}};
Console console=System.console();
System.out.println("***小米的電話簿***");
while(true)
{
int sum=0;
System.out.println("\n1.輸入'all'顯示完整電話簿\n2.輸入姓名查詢目標對象的電話\n3.輸入'end'結束程式");
System.out.print("請在此輸入: ");
name=console.readLine();
if(name.equals("all")==true)
{
System.out.println("編號\t姓名\t電話");
System.out.println("============================");
for(int i=0; i<=4; i++)
{
System.out.print((i+1)+"\t");
for(int j=0; j<=1;j++)
{
System.out.print(tel[i][j]+"\t");
}
System.out.println();
}
continue;
}else if(name.equals("end")==true)
{
break;
}
else
{
for(int i=0; i<=4; i++)
{
if(name.equals(tel[i][0])==true)
{
System.out.println(tel[i][0]+"的電話是"+tel[i][1]);
sum++;
}
}
if(sum==0)
{
System.out.println("查無此人!");
}
continue;
}
}
}
}
複製代碼
作者:
粘靖瑜
時間:
2012-12-15 12:16
import java.io.Console;
public class ch43
{
public static void main(String args[])
{
String name;
String tel[][]={{"大雄","0980-454666"},
{"技安","0911-338888"},
{"宜靜","0922-999579"},
{"阿福","0938-234567"},
{"小叮噹","0911-864356"}};
Console console=System.console();
System.out.println("***小米的電話簿***");
while(true)
{
int sum=0;
System.out.println("1.輸入'all'顯示完整電話簿\n2.輸入性名查尋目標對象的電話\n3.輸入'end'結束程式");
System.out.print("請在此輸入: ");
name=console.readLine();
if(name.equals("all")==true)
{
System.out.println("編號\t姓名\t電話");
System.out.println("==================================");
for(int i=0; i<=4; i++)
{
System.out.print((i+1)+"\t");
for(int j=0; j<=1;j++)
{
System.out.print(tel[i][j]+"\t");
}
System.out.println();
}
continue;
}else if(name.equals("end")==true)
{
break;
}
else
{
for(int i=0; i<=4; i++)
{
if(name.equals(tel[i][0])==true)
{
System.out.println(tel[i][0]+"的電話是"+tel[i][1]);
sum++;
}
}
if(sum==0)
{
System.out.println("查無此人!");
}
continue;
}
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2