1、重复以上过程,直到找到满足条件的记录,使查找成功,或直到子表不存在为止,此时查找不成功。5.声明一个类People,成员变量有姓名、出生日期、性别、身高、体重等;生成10个People类对象,并放在一个以为数组中,编写方法按身高进行排序。/People类public class People private String name; private String birthdaydate; private String sex; private double height; private double weight; public People()/默认构造函数 public People(
2、People p) this.name=p.name; this.birthdaydate=p.birthdaydate; this.sex=p.sex; this.height=p.height; this.weight=p.weight; public People(String name,String birthdaydate,String sex,double height,double weight) this.name=name; this.birthdaydate=birthdaydate; this.sex=sex; this.height=height; this.weigh
3、t=weight; public String getName() return name; public void setName(String name) this.name = name; public String getBirthdaydate() return birthdaydate; public void setBirthdaydate(String birthdaydate) this.birthdaydate = birthdaydate; public String getSex() return sex; public void setSex(String sex)
4、this.sex = sex; public double getHeight() return height; public void setHeight(double height) this.height = height; public double getWeight() return weight; public void setWeight(double weight) this.weight = weight; public String toString() return 姓名:+name+n出生年月:+birthdaydate+n性别:+sex+n身高:+height+n体
5、重:+weight;/test7_5类public class test7_5 /* * param args */ public static void main(String args) / TODO Auto-generated method stub People people= new People(林楚金,1989年8月13日男,182,63.5),诸葛亮181年7月23日,184,76.6),迈克杰克逊1958年8月29日,180,60),乔丹1963年2月17日,198,98.1),拿破仑1769年8月15日,159.5,63),苍井空1983年11月11日女,155,45),
6、; People temp=new People(); for(int i=0;ipeople.length-1;i+) for(int j=i+1;jpeople.length;j+) if(peoplei.getHeight()peoplej.getHeight() temp=peoplej; peoplej=peoplei; peoplei=temp; System.out.println(按身高从小到大排序后的结果如下:); System.out.println(peoplei+n运行结果:6.声明一个类,此类使用私有的ArrayList来存储对象。使用一个Class类的引用得到第一个
7、对象的类型之后,只允许用户插入这种类型的对象。/ Fuck类import java.util.ArrayList;public class Fuck private ArrayList man=new ArrayList(); private Class classType=null; public void add(Object f) if(man.size()=0) classType=f.getClass(); if(classType.equals(f.getClass() man.add(f);插入成功. else System.out.println(只允许插入+getClassT
8、ype()+类的对象. public ArrayList getMan() return man; public Class getClassType() return classType; public Fuck()/test7_6public class test7_6 Fuck fuckman=new Fuck(); String s=new String( fuckman.add(s); fuckman.add(10);/测试插入插入整数 fuckman.add(f/测试插入插入字符 fuckman.add(希特勒 System.out.println(fuckman.getMan()
9、;7.找出一个二维数组的鞍点,即该位置上的元素在所在行上最大,在所在列上最小。(也可能没有鞍点)/test7_7import java.util.Scanner;public class test7_7 public static void main(String args) int row, series, max; boolean T=false; Scanner cin = new Scanner(System.in);请输入数组的行数 row = cin.nextInt();请输入数组的列数 series = cin.nextInt(); int Array = new introws
10、eries; int R = new introw;/ 记录每行最大的数的列标 int S = new intseries;/ 记录每列最小的数的行标请输入数组内容 for (int i = 0; i Array.length; i+) for (int j = 0; j Arrayi.length; j+) Arrayij = cin.nextInt(); if(j=series-1) max = Arrayi0; for (int z = 1; z max) max = Arrayiz; Ri = z; Array0.length; max = Array0j; row ; if (Arrayzj max = Arrayzj; Sj = z;Array.length; if(SRi=i)鞍点:+Array+i+Ri+ :+ArrayiRi+ T=true; if(T=false)没有鞍点
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1