netbeans 怎么添加构造函数
1个回答
2016-07-24
展开全部
importjava.io.DataOutputStream;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importjava.util.ArrayList;importjava.util.HashSet;importjava.util.Hashtable;importjava.util.Iterator;/***(1)编写一个学生类,有姓名,年龄,性别属性,创建若干学生对象分别保存到HashSet,*ArrayList,Hashtable中,并利用迭代器Iterator将姓名,年龄,性别打印出来。**/classStudent{Stringname;intage;Stringsex;Student(Stringname,intage,Stringsex){this.name=name;this.age=age;this.sex=sex;}publicStringtoString(){returnname+""+age+""+sex;}}publicclassHomeWork{publicstaticvoidmain(Stringargs[])throwsIOException{Studenta=newStudent("zhangsan",23,"男");Studentb=newStudent("zhangsan1",23,"男");Studentc=newStudent("zhangsan2",23,"男");HashSetset=newHashSet();Hashtabletable=newHashtable();table.put("a",a);table.put("b",b);table.put("c",c);//set.add(a);//set.add(b);//set.add(c);//Iteratorit=set.iterator();Iteratorit=table.keySet().iterator();while(it.hasNext()){System.out.println(it.next());}it=table.values().iterator();while(it.hasNext()){System.out.println(it.next());}}}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询