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);
}
}

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

时间: 2024-10-10 04:33:13

mit java open course assignment #2的相关文章

mit java open course assignment #4

package come; public class Library { // Add the missing implementation to this class String realLocation; String[][] bookCollection = new String[2][10]; int index = 0; public Library(String Location) { realLocation = Location; } static void printOpen

Java基础-赋值运算符Assignment Operators与条件运算符Condition Operators

Java基础-赋值运算符Assignment Operators与条件运算符Condition Operators 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.赋值运算符 表达式的数据类型要与左边变量的类型兼容 1>.常规赋值 1 /* 2 @author :yinzhengjie 3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/ 4 EMAIL:[email protected]

Java实习生面试题整理

一.数据类型 包装类型 八个基本类型: boolean/1 byte/8 char/16 short/16 int/32 float/32 long/64 double/64 基本类型都有对应的包装类型,基本类型与其对应的包装类型之间的赋值使用自动装箱与拆箱完成. ? 1 2 Integer x = 2;     // 装箱 int y = x;         // 拆箱 缓存池 new Integer(123) 与 Integer.valueOf(123) 的区别在于: new Intege

java面试之java 基础

一.数据类型基本类型包装类型缓存池 二.String概览不可变的好处String, StringBuffer and StringBuilderString Poolnew String("abc") 三.运算参数传递float 与 double隐式类型转换switch 四.关键字finalstatic 五.Object 通用方法概览equals()hashCode()toString()clone() 六.继承访问权限抽象类与接口super重写与重载 七.反射 八.异常 九.泛型 十

最全的静态网站生成器(开源项目)

将动态网页静态化,可以有效减轻服务器端的压力,并且静态网页的访问速度要快于动态网页.此外,使用静态网页还有利于搜索引擎的收录,从而提高网站的搜索排名. 下面是StaticSiteGenerators网站收集整理的开源的静态网站生成器,按照编程语言进行分类,每个分类按照Star数进行排序. (关注ITeye官微,随时随地查看最新开发资讯.技术文章.) 目 录 [ - ] JavaScript 版 Ruby 版 Java/Groovy/Scala 版 PHP 版本 Python 版 Go 语言版 P

JStorm之Topology调度

topology在服务端提交过程中,会经过一系列的验证和初始化:TP结构校验.创建本地目录并拷贝序列化文件jar包.生成znode用于存放TP和task等信息,最后一步才进行任务分配,如下图: 提交主函数位于ServiceHandler.java中 private void makeAssignment(String topologyName, String topologyId, TopologyInitialStatus status) throws FailedAssignTopology

CSCI3120

CSCI3120Assignment 1Due: 11:59 AM, Tuesay, May 28, 2019IntroductionThe concepts applicable to operating systems are applicable in many other systems as well.For example, manufacturing, transportation, and bureaucracies. The air transportationsystem (

Web-crawler

导航 (返回顶部) 1. spider 1.1 robots.txt 1.2 ads.txt 1.3 security.txt 1.4 blogger.com 上的 robots.txt和ads.txt 2. 爬虫软件列表 2.1 介绍一些比较方便好用的爬虫工具和服务 2.2 33款可用来抓数据的开源爬虫软件工具(全都没试过) 3. 更多相关 1. spider 1.1 robots.txt 1.2 ads.txt 1.3 security.txt 1.4 blogger.com 上的 robo

AlgorithmsI Programming Assignment 1: PercolationStats.java

import edu.princeton.cs.algs4.StdOut; import edu.princeton.cs.algs4.StdRandom; import edu.princeton.cs.algs4.StdStats; /* *How do I generate a site uniformly at random among all blocked sites for use in PercolationStats? * Pick a site at random (by u