当前位置:网站首页>Basic use of array -- traverse the circular array to find the maximum value, minimum value, maximum subscript and minimum subscript of the array
Basic use of array -- traverse the circular array to find the maximum value, minimum value, maximum subscript and minimum subscript of the array
2022-07-29 05:53:00 【Don't want bald Xiao Yang】
Traverse the circular array to find the maximum value of the array , Minimum and maximum subscripts , Minimum subscript
package com.qy151.test5;
import java.util.Scanner;
/**
* @unthor : YSH
* @date : 11:10 2022/6/20
*/
public class Test6 {
public static void main(String[] args) {
// Get the maximum . And the subscript of the maximum
// Get the minimum , And the subscript of the minimum value
int[] nums={45,32,12,67,89,56,99,23,2,65};
// 0 1 2 3 4 5 6 7 8 9
// Output the maximum value through the subscript of the maximum value
// Output the minimum value through the subscript of the minimum value
//System.out.println(nums[4]);
//System.out.println(nums[2]);
// Define the maximum position
int maxPos=0;
// Define the minimum position
int minPos=0;
for (int i=1;i<nums.length;i++){
// Get data by subscript , Compare
// Compare the data in the corresponding position
if (nums[maxPos]<nums[i]){
// Where to record data
maxPos=i;
}
// If the data corresponding to the lowest subscript is not the smallest , At this time, the minimum subscript is used to store the traversed subscript data
if (nums[minPos]>nums[i]){
// Save subscript
minPos=i;
}
}
System.out.println(" The subscript of the maximum value :"+maxPos+" The corresponding maximum value :"+nums[maxPos]);
System.out.println(" Subscript of minimum value :"+minPos+" The corresponding minimum value :"+nums[minPos]);
}
}边栏推荐
- 如何在加密市场熊市中生存?
- 30 knowledge points that must be mastered in quantitative development [what is level-2 data]
- C# 连接 SharepointOnline WebService
- Breaking through the hardware bottleneck (I): the development of Intel Architecture and bottleneck mining
- D3.JS 纵向关系图(加箭头,连接线文字描述)
- asyncawait和promise的区别
- Xsan is highly available - xdfs and San are integrated with new vitality
- 重庆大道云行作为软件产业代表受邀参加渝中区重点项目签约仪式
- 30 knowledge points that must be mastered in quantitative development [what is individual data]?
- 识变!应变!求变!
猜你喜欢

麦当娜“Hellbent”购买130万美元的nft无聊猿,现在被认为太贵了

Process management of day02 operation

Fantom (FTM) prices will soar by 20% in the next few days

手撕ORM 框架(泛型+注解+反射)

Fantom (FTM) 价格将在未来几天飙升 20%

Novice introduction: download from PHP environment to thinkphp6 framework by hand

超简单集成HMS ML Kit 人脸检测实现可爱贴纸

Detailed steps of JDBC connection to database

农村品牌建设给年轻人的一些机会

与张小姐的春夏秋冬(2)
随机推荐
与张小姐的春夏秋冬(3)
Read and understand move2earn project - move
30 knowledge points that must be mastered in quantitative development [what is level-2 data]
打印出1-100之间的所有质数
Super simple integration of HMS ml kit to realize parent control
DeFi 2.0的LaaS协议,重振DeFi赛道发展的关键
iSCSI vs iSER vs NVMe-TCP vs NVMe-RDMA
一文读懂Move2Earn项目——MOVE
Laravel swagger add access password
Training log 7 of the project "construction of Shandong University mobile Internet development technology teaching website"
DAO赛道异军突起,M-DAO的优势在哪里?
“山东大学移动互联网开发技术教学网站建设”项目实训日志二
The completely decentralized programming mode does not need servers or IP, just like a aimless network extending everywhere
Win10+opencv3.2+vs2015 configuration
熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
手撕ORM 框架(泛型+注解+反射)
中海油集团,桌面云&网盘存储系统应用案例
SQL repair duplicate data
华为2020校招笔试编程题 看这篇就够了(上)
XDFS&空天院HPC集群典型案例