zoukankan      html  css  js  c++  java
  • mit java open course assignment #2

    package come;
    
    public class Marothon {
    
        public static void FirstName(String[] args1,int[] args2){
            int MinIndex,MinTime,i;
            MinTime = 10000;
            MinIndex = 0;
            for(i = 0; i < 16; i++){
                if (args2[i] < MinTime){
                    MinTime = args2[i];
                    MinIndex = i; 
                }
            }
            System.out.println(args1[MinIndex] + " "+MinTime);
        }
        public static void SecondName(String[] args1, int[] args2){
            int SmallIndex,SmallerIndex,Small,Smaller,i;
            Small = 10000;
            Smaller = 10000;
            SmallerIndex = 100;
            SmallIndex =101;
            for(i = 0; i<16; i++){
                if(args2[i] < Small && args2[i] > Smaller){
                    Small = args2[i];
                    SmallIndex = i;
                }else if(args2[i] < Smaller){
                    Small = Smaller;
                    Smaller = args2[i];
                    SmallIndex = SmallerIndex;
                    SmallerIndex = i;
                }
            }
            System.out.println(args1[SmallIndex] + " " + args2[SmallIndex]);
        }
        public static void main(String[] args){
            // TODO Auto-generated method stub
            String[] names = {"Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex",
                    "Emma", "John", "James", "Jane", "Emily", "Daniel", "Neda",
                    "Aaron", "Kate"};
            int[] times = {341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299,
                    343, 317, 265};
            SecondName(names,times);
    }
    }
    View Code

    SecondName函数只遍历了一次数组,大大提升了之前想用FirstName遍历一次后用if避开最小的来做,不过就要遍历两次,哈哈哈,不错

  • 相关阅读:
    UDP
    ICMP协议、DNS、ARP协议、ping、DHCP协议
    OSI七层模型和TCP/IP四层模型
    STL六大组件
    迭代器
    哈希表
    react wangeditor使用
    URL切割
    ES6对象合并
    nginx 访问本机文件
  • 原文地址:https://www.cnblogs.com/gabygoole/p/4802817.html
Copyright © 2011-2022 走看看