package com.ww.yzpA; public class Students { int No; int Height; } package com.ww.yzpA; public class Height { public Students getMaxHeigth(Students[] str) { Students A = new Students(); for (int i = 0; i < str.length; i++) { if (str[i].Height > A.Height) { A.Height = str[i].Height; A.No = str[i].No; } } return A; } } package com.ww.yzpA; import java.util.Scanner; public class Text { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner (System.in); Students [] stu = new Students[10]; Height news=new Height(); Students Stu=new Students(); for (int i = 0; i < stu.length; i++) { System.out.println("请输入第"+(i+1)+"位学员的身高:"); stu[i]= new Students(); stu[i].Height=in.nextInt(); stu[i].No=i+1; } Stu=news.getMaxHeigth(stu); System.out.print("该班第"+Stu.No+"名学生身高最高,为"+Stu.Height); } }
Java-第十四章-代参的方法(二)-编程实现,输入班里10名学生的身高,获得身高最高的学生要求对象数组类型方法,布布扣,bubuko.com
Java-第十四章-代参的方法(二)-编程实现,输入班里10名学生的身高,获得身高最高的学生要求对象数组类型方法
原文地址:http://wenwen520.blog.51cto.com/8956560/1427219