package main
import (
"fmt"
) func main() { //获取一个数组里最大值,并且拿到下标 //声明一个数组5个元素
var arr []int = [...]int {, , , ,}
//假设第一个元素是最大值,下标为0
maxVal := arr[]
maxIndex := for i := ; i < len(arr); i++ {
//从第二个 元素开始循环比较,如果发现有更大的,则交换
if maxVal < arr[i] {
maxVal = arr[i]
maxIndex = i
}
} fmt.Printf("maxVal=%v, maxIndex=%v", maxVal, maxIndex)
}
maxVal=, maxIndex=

Golang获取int数组里的最大值和下标的更多相关文章

  1. PHP里获取一维数组里的最大值和最小值

    <?php $arr = ['10','100','50','90','2','5']; $min = min($arr); $max = max($arr); echo $min.PHP_EO ...

  2. C#获取一个数组中的最大值、最小值、平均值

    C#获取一个数组中的最大值.最小值.平均值 1.给出一个数组 ,,,,,-,,,,}; 2.数组Array自带方法 本身是直接可以调用Min(),Max(),Average()方法来求出 最小值.最大 ...

  3. PHP获取以为数组中的最大值和最小值

    1.PHP获取一维数组中的最大值 <?php $a=array('1','3','55','99'); $pos = array_search(max($a), $a); echo $a[$po ...

  4. js 数组里求最大值和最小值

    // 数组里相邻两个数做比较 取满足条件的那个(以此类推) var arr = [1,3,4,5,6,7]; function Max(array){ var max = array[0]; for( ...

  5. 获取checkbox数组 里面的值

    echo '<td class="text-left"><input  name="tids[]" type="checkbox&q ...

  6. 常用的函数式接口_Supplier和常用的函数式接口Supplier接口练习_求数组中元素最大值

    Supplier接口 package com.yang.Test.SupplierStudy; import java.util.function.Supplier; /** * 常用的函数式接口 * ...

  7. day5 数组对角线及最大值

    1.输出M行M列数组方针,求对角线元素和#define M 5void fun(int xx[][M], int n)//n行n列{ int i = 0; int sum = 0; for (i = ...

  8. C# 之 将string数组转换到int数组并获取最大最小值

    1.string 数组转换到 int 数组 " }; int[] output = Array.ConvertAll<string, int>(input, delegate(s ...

  9. JavaScript获取数组最小值和最大值的方法

    本文实例讲述了JavaScript获取数组最小值和最大值的方法.分享给大家供大家参考.具体如下: ? 1 2 3 4 5 6 var arr = new Array(); arr[0] = 100; ...

随机推荐

  1. centos6下升级git版本的操作记录

    编译go_ethereum的时候出现了错误 然后发现是自己的git没有升级成功  因为编译需要高版本的git版本  所以会编译不成功  之后执行 root@uatjenkins01 ~]# git - ...

  2. (转)Marathon健康检查

    健康检查是需要每个应用运行监控检查任务的. 1.默认的健康检查是延迟才能让mesos知道任务的状态是否健康. 2.marathon提供一个任务资源的健康成员访问的REST API接口. 如果HTTP的 ...

  3. vue中使用hotcss--stylus

    页面中一直闪动这个. 后面改成scss后还是这样.还不知道原因

  4. android 调用webview控件,为逆向h5app做准备

    activity对应layout文件加入: <WebView android:id="@+id/main_web" android:layout_width="ma ...

  5. Selenium基础知识(五)多窗口切换

    说到多窗口切换必须想到driver.switch_to.window()方法 driver.switch_to.window() 实现在不同窗口之间切换 driver.current_window_h ...

  6. [提权] 脏牛漏洞 Dirty COW CVE-2016-5195 2.6.22 < 3.9 (x86/x64)

    /* * (un)comment correct payload first (x86 or x64)! * * $ gcc cowroot.c -o cowroot -pthread * $ ./c ...

  7. Windows搭建react-native开发环境

    一.目标平台 windows+android 1. 必须软件 python2+ nodejs npm 2. 安装react-native命令行 $ npm install -g react-nativ ...

  8. mysql常用参数监控

      1.系统mysql的进程数 ps -ef | grep "mysql" | grep -v "grep" | wc –l 2.Slave_running m ...

  9. word中加入endnote

    http://jingyan.baidu.com/article/f54ae2fc3926d91e92b849c2.html 1.如果安装完endnote后,word中没有出现 endnote菜单,则 ...

  10. java中二维数组的复制克隆

    https://blog.csdn.net/qq_37232304/article/details/79950022