想不出來!!

alderchew82 2006-03-13 02:03:19
小弟我才剛學JAVA,老師就出了這些題目
可是我覺得好難都寫不出來,還是說這些題目其實很簡單啊
可以請各位大大幫我解答嗎?

如何写指令, 在console 里,让使用者选择并显示在console , 比如

<A>dd contact or <S>how contacts: a <-----使用者输入
<B>usiness or <P>ersonnal Contact: b <---使用者输入
Enter name: XXX <---使用者输入
Enter company: WWW <---使用者输入
Enter mail : XXX <---使用者输入
<A>dd contact or <S>how contacts: a <-----使用者输入
<B>usiness or <P>ersonnal Contact: P <---使用者输入
Enter name: XXX111 <---使用者输入
Enter company: WWW111 <---使用者输入
Enter mail : XXX111 <---使用者输入
<A>dd contact or <S>how contacts: s <-----使用者输入
------
Business Contact
------
xxx
www
xxx
----
Personal Contact
----
xxx111
www111
xxx111
...全文
165 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bgceft 2006-03-23
  • 打赏
  • 举报
回复
UP
zx2002027 2006-03-13
  • 打赏
  • 举报
回复
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.*;
class Business{
private String name;
private String company;
private String mail;

public void setName(String name){
this.name=name;
}

public String getName(){
return this.name;
}

public void setCompany(String comp){
this.company=comp;
}

public String getCompany(){
return this.company;
}

public void setMail(String m){
this.mail=m;
}

public String getMail(){
return this.mail;
}

}

public class test1 {
public static void main(String[] args) throws IOException{
ArrayList al=new ArrayList();
ArrayList a2=new ArrayList();
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
String s="";
System.out.print ("<A>dd new contact or <S>how contacts?");
s=br.readLine();
while(!s.equals("s")){
if(s.equals("a")){
System.out.print ("<B>usiness or <P>ersonnal Contact:");
s=br.readLine();
if(s.equals("b")){
Business b = new Business();
System.out.print("Enter Name: ");

s=br.readLine();
b.setName(s);
System.out.print("Enter Company: ");
s=br.readLine();
b.setCompany(s);
System.out.print("Enter Mail: ");
s=br.readLine();
b.setMail(s);
//}
al.add(b);
System.out.print ("<A>dd new contact or <S>how contacts?");
s=br.readLine();
}
}
}
for(int i=0;i<al.size();i++){

System.out.println("name:"+((Business)al.get(i)).getName());
System.out.println("company:"+((Business)al.get(i)).getCompany());
System.out.println("Mail:"+((Business)al.get(i)).getMail());
}

in.close();
br.close();
}
} ///:~

剩下部分LZ自己补完就行了
zx2002027 2006-03-13
  • 打赏
  • 举报
回复
用while循环读入
lydvqq 2006-03-13
  • 打赏
  • 举报
回复
while(1==1){
int c = br.read();
if(?)break;
}
alderchew82 2006-03-13
  • 打赏
  • 举报
回复
System.out.print ("<A>dd new contact or <S>how contacts?");
//System.out.flush(); // empties buffer, before you input text
int selectAS = bufRead.read();

if ( selectAS == 65)
{
System.out.print("<B>usiness or <P>ersonal Contact?");
int BP = bufRead.read();

System.out.println( "test" );

if (BP == 'B')
{
System.out.print("Enter Name: ");
String messageB = bufRead.readLine();
System.out.print("Enter Company: ");
messageB = bufRead.readLine();
System.out.print("Enter Email: ");
messageB = bufRead.readLine();
}
else if (BP == 'P')
{
System.out.print("Enter Name: ");
String messageP = bufRead.readLine();
System.out.print("Enter Address: ");
messageP = bufRead.readLine();
System.out.print("Enter phone: ");
messageP = bufRead.readLine();
}
else{System.exit(0);}
}


我可以写入第一次,但是第二次的输入, 不让我输入。。
好像int BP = bufRead.read(); 并没有执行
lydvqq 2006-03-13
  • 打赏
  • 举报
回复
import java.io.*;
public class test {


把下面这个完成就OK了.
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("<A>dd contact or <S>how contacts: ");
String s = null;
s=br.readLine();
}
}

alderchew82 2006-03-13
  • 打赏
  • 举报
回复
小弟找不到。。请高手赐教
wilowind 2006-03-13
  • 打赏
  • 举报
回复
非常简单的, 到处都有实例。 就是一个简单的io

62,625

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧