当前位置:网站首页>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 :

边栏推荐
- sql语句练习题整理
- Wet- a good choice for people with English difficulties - console translation
- [fan Tan] in detail: lower control, upward management, upward drawing cake.
- Acwing 866. determining prime numbers by trial division
- Redis memory elimination mechanism?
- In Oracle 19C version, logminer package continuous_ The outdated function of mine leads to CDC failure
- 『Skywalking』. Net core fast access distributed link tracking platform
- [51Nod1676 无向图同构]无向图哈希[通俗易懂]
- 『SignalR』.NET使用 SignalR 进行实时通信初体验
- 关于接口测试你想知道的都在这儿了
猜你喜欢

JMeter websocket interface test

The automation testing post spent 20K recruiting, but in the end, there was no suitable one. Both fresh students are better than them

Special class design

How to implement an app application to limit users' time use?

All you want to know about interface testing is here

What have I experienced to become a harder tester than development?

What is partition and barrel division?

2022 love analysis ― bank digitalization practice report

GPON introduction and Huawei OLT gateway registration and configuration process

Redis usage details
随机推荐
[dinner talk] those things that seem to be for the sake of the company but are actually incomprehensible (2: soft quality "eye edge" during interview)
五种分配方式是否会产生内部碎片、外部碎片
Redis master-slave architecture lock failure problem (master-slave)
Don't know mock test yet? An article to familiarize you with mock
Mouseevent event -- mouse coordinate description -- Focus event -- input event -- throttle -- mousewheel (wheel event)
YUV420 YUV420sp 图像格式「建议收藏」
C language: random generated number + bubble sort
『Skywalking』. Net core fast access distributed link tracking platform
The testing work is not valued. Have you changed your position?
3. Editors (vim)
Jmeter--- set proxy recording request
虚拟内存与磁盘
QML module not found
核电站在席卷欧洲的热浪中努力保持安全工作
2022最新软件测试八股文,能不能拿心仪Offer就看你背得怎样了
LeetCode_ 93_ Restore IP address
Excuse me, how to deal with repeated consumption of MySQL data
2年功能测试,却感觉自己什么都不会,2022我该何去何从?
Bitcoin.com:usdd represents a truly decentralized stable currency
磁盘空间的三种分配方式