java作业之地址簿2011/9/12
import java.util.Scanner;
public class Address {
String name;
String city;
String email;
//构造函数
public Address(String Myname,String Mycity,String Myemail)
{
name=Myname;
city=Mycity;
email=Myemail;
}
//toString()方法就是把对象转换成String类型
public String toString()
{
return name+" "+city+" "+email;
}
public static void main(String args[])
{
//新建两个对象
//Address address1= new Address("Daiyuegeng","
//Address address2= new Address("Zhouhuaming","
Address address3= new Address("","","");
Scanner reader=new Scanner(System.in);
System.out.println("亲,请输入你的姓名:");
address3.name=reader.next();
System.out.println("亲,请输入你的城市:");
address3.city=reader.next();
System.out.println("亲,请输入你的邮箱号:");
address3.email=reader.next();
//输出
//System.out.println(address3.name);
//System.out.println(address3.city);
//System.out.println(address3.email);
//System.out.println(address1);
//System.out.println(address2);
System.out.println(address3);
}
}
运行结果:
亲,请输入你的姓名:
戴月耿
亲,请输入你的城市:
温州
亲,请输入你的邮箱号:
325035
戴月耿 温州 325035