当前位置:网站首页>Randomly generate 10 (range 1~100) integers, save them to the array, and print the array in reverse order. And find the average value, the maximum value and the subscript of the maximum value, and fin
Randomly generate 10 (range 1~100) integers, save them to the array, and print the array in reverse order. And find the average value, the maximum value and the subscript of the maximum value, and fin
2022-07-25 22:08:00 【Bao Zhou Pao】
package array;
public class Homework02 {
public static void main(String[] args){
int[] arr=new int[10];
int i,index=0;
int max=arr[0];
// Randomly generate integers
System.out.println(" The randomly generated array is :");
for(i=0;i<arr.length;i++){
arr[i]=(int)(Math.random()*100+1);
System.out.print(arr[i]+" ");
}
System.out.println();
int j;
double averge;
int sum=0;
System.out.println(" Print array in reverse order :");
for(j=arr.length-1;j>=0;j--){// Print in reverse order
System.out.print(arr[j]+" ");
sum+=arr[j];
if(max<arr[j]){// Find the maximum value and the subscript of the maximum value
max=arr[j];
index=j;
}
}
System.out.println();
// Determine whether the array contains values 8
int k=0,n=0;
while(k<arr.length){
if(arr[k]==8){
n++;
System.out.println(" The array contains "+n+" A numerical 8");
break;
}
k++;
if(k==10){
System.out.println(" The array does not contain numeric values 8");
}
}
averge=sum/10;
System.out.println(" The average value is :"+averge);
System.out.println(" The maximum value is :"+max+"\n"+" The maximum subscript is :"+index);
}
}
Examples of run results :

边栏推荐
- [fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
- Open source RSS subscriber freshrss
- Playwright tutorial (II) suitable for Xiaobai
- At present, flynk CDC does not support mysql5.5. If you change the source code and release this restriction, there will be a lot of data problems?
- Application of breakthrough thinking in testing work
- Redis内存淘汰机制?
- 2022 love analysis ― bank digitalization practice report
- Detailed summary of C language game dual cache to solve the flash screen problem [easy to understand]
- 如何将一个域名解析到多个IP地址?
- Wechat applet application development competition works comprehensive development record - Jinlu cultural tourism (cloud development - Overview)
猜你喜欢

Three ways to allocate disk space

【饭谈】如何设计好一款测试平台?

手机端微信发朋友圈功能测试点总结

Imitation Tiktok homepage interface

开源的RSS订阅器FreshRSS

Bitcoin.com:usdd represents a truly decentralized stable currency
![[hand torn STL] unordered_ set、unordered_ Map (encapsulated with hash table)](/img/33/08f7b72ce99e07821a1f4b6e594e13.png)
[hand torn STL] unordered_ set、unordered_ Map (encapsulated with hash table)

Whether the five distribution methods will produce internal fragments and external fragments

Animation curves are used every day. Can you make one by yourself? After reading this article, you will!

Solutions to the failure of win key in ikbc keyboard
随机推荐
面了个腾讯三年经验的测试员,让我见识到了真正的测试天花板
Bitcoin.com:usdd represents a truly decentralized stable currency
The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?
五种分配方式是否会产生内部碎片、外部碎片
YUV420 YUV420sp 图像格式「建议收藏」
kubernetes之VictoriaMetrics单节点
如何快速搭建图片服务器[通俗易懂]
golang : MVC之models
【GO基础02】第一个程序
c sqlite ... ...
『SignalR』.NET使用 SignalR 进行实时通信初体验
All you want to know about interface testing is here
The testing work is not valued. Have you changed your position?
C语言:随机生成数+选择排序
synchronized与volatile
Don't know mock test yet? An article to familiarize you with mock
ZigBee development board (nxpzigbee Development)
EL表达式改进JSP
Why does redis choose single thread?
『Skywalking』. Net core fast access distributed link tracking platform