Golang获取int数组里的最大值和下标
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数组里的最大值和下标的更多相关文章
- PHP里获取一维数组里的最大值和最小值
<?php $arr = ['10','100','50','90','2','5']; $min = min($arr); $max = max($arr); echo $min.PHP_EO ...
- C#获取一个数组中的最大值、最小值、平均值
C#获取一个数组中的最大值.最小值.平均值 1.给出一个数组 ,,,,,-,,,,}; 2.数组Array自带方法 本身是直接可以调用Min(),Max(),Average()方法来求出 最小值.最大 ...
- PHP获取以为数组中的最大值和最小值
1.PHP获取一维数组中的最大值 <?php $a=array('1','3','55','99'); $pos = array_search(max($a), $a); echo $a[$po ...
- js 数组里求最大值和最小值
// 数组里相邻两个数做比较 取满足条件的那个(以此类推) var arr = [1,3,4,5,6,7]; function Max(array){ var max = array[0]; for( ...
- 获取checkbox数组 里面的值
echo '<td class="text-left"><input name="tids[]" type="checkbox&q ...
- 常用的函数式接口_Supplier和常用的函数式接口Supplier接口练习_求数组中元素最大值
Supplier接口 package com.yang.Test.SupplierStudy; import java.util.function.Supplier; /** * 常用的函数式接口 * ...
- day5 数组对角线及最大值
1.输出M行M列数组方针,求对角线元素和#define M 5void fun(int xx[][M], int n)//n行n列{ int i = 0; int sum = 0; for (i = ...
- C# 之 将string数组转换到int数组并获取最大最小值
1.string 数组转换到 int 数组 " }; int[] output = Array.ConvertAll<string, int>(input, delegate(s ...
- JavaScript获取数组最小值和最大值的方法
本文实例讲述了JavaScript获取数组最小值和最大值的方法.分享给大家供大家参考.具体如下: ? 1 2 3 4 5 6 var arr = new Array(); arr[0] = 100; ...
随机推荐
- 【LeetCode每天一题】Container With Most Water(容器中最多的水)
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...
- git push 报错:you are not allowed to upload merges
git rebase Cannot rebase: You have unstaged changes. git stash # 每次 push 前 git pull --rebase git pus ...
- 26-Python3 面向对象
26-Python3 面向对象 ''' 面向对象技术简介 ''' ''' 类定义 ''' ''' 类对象 ''' class MyClass: i = 12345 def f(self): retur ...
- [Java in NetBeans] Lesson 04. Class / Objects
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Class: Blueprint for an object. (e.g. dog is a class) Object: cust ...
- Redis:C#使用Redis(1)
一.安装 1.下载安装包: 官方网站:redis.io 官方推荐windows版本:https://github.com/MSOpenTech/redis 2:下载压缩包,解压后如下 redis-se ...
- lldb使用
常用 si,ni ,ex, mem,di,reg,b,c,x 以下内容是lldb帮助文档中内容: apropos -- List debugger commands related ...
- C++ 执行 cmd 命令 删除文件 删除注册表项
#include <Windows.h> WinExec("cmd /C \"del C:\\Windows\\secretWin.ini\"",S ...
- base64的编码
计算机中的数据一般是由ascii编码,来存储的, 0---31以及127,表示的是控制字符: 32-126表示的是字符,包括空格,阿拉伯数字,大小写字母: 之后的128个字符,是不可见的字符, 在网络 ...
- spring 框架的优点
谈spring 框架的优点就是说spring 框架2大核心技术的优点 1. 控制反转:控制反转是将对象的创建和管理交给spring容器,已经管理对象之间的依赖关系, 那么将对象的创建和生命周期的管理交 ...
- 01 while 循环输入1 2 3 4 5 6 8 9 10
start = 1while True: if start == 7: start += 1 continue print(start) start ...