正在加载图片...
Person array Processing-3 r Find the youngest and oldest persons int minix //index to the youngest person maxIdx =0 //index to the oldest person person if( person [i]. getAge()< person [minIdx] getAge())i minix //found a younger person else if (person [i]. getAge()> person [maxIdx getAge())i maids //found an older person //person [minIdx] is the youngest and person [maxIdx] is the oldest C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 9-17© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 9 - 17 Person Array Processing - 3 Find the youngest and oldest persons. int minIdx = 0; //index to the youngest person int maxIdx = 0; //index to the oldest person for (int i = 1; i < person.length; i++) { if ( person[i].getAge() < person[minIdx].getAge() ) { minIdx = i; //found a younger person } else if (person[i].getAge() > person[maxIdx.getAge() ) { maxIdx = i; //found an older person } } //person[minIdx] is the youngest and person[maxIdx] is the oldest
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有