当前位置:网站首页>Day012 application of one-dimensional array
Day012 application of one-dimensional array
2022-07-27 07:01:00 【Mo Nian】
There is a group of students' achievements {99,85,82,63, 60}, Arrange them in descending order .
To increase the performance of a student , Insert it into the grade sequence , And keep descending .
Ideas :
1) Create a new array that is longer than the original array 1 Array of
2) Store the elements in the original array into the new array in order
3) Use Scanner Gain and increase students' achievements
4) Get the position of the inserted element to be inserted through circular comparison
5) The elements starting from the insertion position and then
int[] scores = { 99, 85, 82, 63, 60 };
// 1) Create a new array that is longer than the original array 1 Array of
int[] newScores = new int[scores.length + 1];
// 2) Store the elements in the original array into the new array in order
for (int i = 0; i < scores.length; i++) {
newScores[i] = scores[i];
}
// 3) Use Scanner Gain and increase students' achievements
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter the student grade you want to increase :");
int insert = sc.nextInt();
// 4) Get the position of the inserted element to be inserted through circular comparison
int index=newScores.length-1;
for (int i = 0; i < newScores.length; i++) {
if(insert>newScores[i]){
index=i;
// Once the obtained element meets the conditions , No more comparisons
break;
}
}
// 5) Move back one bit from the insertion position and the following elements ( Be careful : When moving , Move back and forth ; Subscript from 0 At the beginning )
for(int i = newScores.length-1;i>index;i--){
newScores[i]=newScores[i-1];
}
// 6) Put the inserted element in the corresponding position
newScores[index]=insert;
// Traverse
for(int i=0;i<newScores.length;i++){
System.out.print(newScores[i]+" ");
}
边栏推荐
- Deepsort工作原理分析
- Matlab drawing (ultra detailed)
- PNA modified polypeptide arms PNA PNA DNA suc aapf PNA suc - (ALA) 3 PNA
- deepsort源码解读(三)
- About the new features of ES6
- Peptide nucleic acid oligomer containing azobenzene monomer (nh2-tnt4, n-pnas) Qiyue biological customization
- GoLand writes Go program
- DNA modified near infrared two region GaAs quantum dots | GaAs DNA QDs | DNA modified GaAs quantum dots
- CdS quantum dots modified DNA | CDs DNA QDs | near infrared CdS quantum dots coupled DNA specification information
- ZnS-DNA QDs近红外硫化锌ZnS量子点改性脱氧核糖核酸DNA|DNA修饰ZnS量子点
猜你喜欢

强网杯2021 pwn 赛题解析——babypwn

CentOS上使用Docker安装和部署Redis

Multimodal database | star ring technology multimode database argodb "one database for multiple purposes", building a high-performance Lake warehouse integrated platform

To improve the baby's allergy, take yiminshu. Azg and aibeca love la Beijia work together to protect the growth of Chinese babies

FTX Foundation funded 15million to help covid-19 clinical trials, which will affect global public health

AI:业余时间打比赛—挣它个小小目标—【阿里安全×ICDM 2022】大规模电商图上的风险商品检测比赛

Qi Yue: thiol modified oligodna | DNA modified cdte/cds core-shell quantum dots | DNA coupled indium arsenide InAs quantum dots InAs DNA QDs

PNA polypeptide PNA TPP | GLT ala ala Pro Leu PNA | suc ala Pro PNA | suc AAPL PNA | suc AAPM PNA

基于SSM音乐网站管理系统

Why can cross entropy loss be used to characterize loss
随机推荐
Soul submitted an application for listing in Hong Kong stocks, accelerating the diversified and scene based layout of social gathering places
Ftx.us launched stock and ETF trading services to make trading more transparent
Reasoning speed of model
Significance of NVIDIA SMI parameters
Express框架
C语言怎么学?这篇文章给你完整答案
The issuing process of individual developers applying for code signing certificates
如何删除或替换EasyPlayer流媒体播放器的loading样式?
After adding a camera (camera) to the UAV in gazebo, the UAV cannot take off
基于SSM实现的校园新闻发布管理系统
PNA polypeptide PNA TPP | GLT ala ala Pro Leu PNA | suc ala Pro PNA | suc AAPL PNA | suc AAPM PNA
Redis fast learning
DNA modified near infrared two region GaAs quantum dots | GaAs DNA QDs | DNA modified GaAs quantum dots
DataScience:数据生成之在原始数据上添加小量噪声(可自定义噪声)进而实现构造新数据(dataframe格式数据存储案例)
Multimodal database | star ring technology multimode database argodb "one database for multiple purposes", building a high-performance Lake warehouse integrated platform
【Latex格式】双栏双图左右并排有小标题、上下并列有小标题
Express framework
EasyCVR平台播放设备录像时,拖动时间轴播放无效是什么原因?
PNA peptide nucleic acid modified peptide suc Tyr Leu Val PNA | suc ala Pro Phe PNA 11
运行代码报错: libboost_filesystem.so.1.58.0: cannot open shared object file: No such file or directory