求数值型数组中元素的最大值、最小值、平均值、总值等
package com.mxf.test;
/*
* 题目:定义一个int型的一维数组,包含10个元素,赋值一些随机整数(两位数)
* 求出所有元素的最大值、最小值、和值、平均值并输出
*/
public class Test4 {
public static void main(String[] args) {
int[] arr = new int[10];
//2位数:10~99 99-10+1=90,+10
for(int i=0;iarr[i]) {
min = arr[i];
}
}
System.out.println("最小值为:"+min);
//求数组元素的总和
int sum = 0;
double average = 0;
for(int i=0;i
数组的复制、反转、查找(线性查找、二分法查找)
//1. 数组的复制,注意区分于数组之间的赋值(地址值)
public class Test5 {
public static void main(String[] args) {
int[] array1 = new int[] {2,3,5,7,11,13,17,19};
int[] array2 ;
array2 = new int[array1.length];
for(int i=0;i
//2. 数组的反转
for(int i=0;i
//3.数组的查找
//3.1线性查找
int dest = 11;
boolean flag = true;
for(int i=0;iarray1[mid]) {
head = mid+1;
}else {
end = mid-1;
}
}
if(isFlag) {
System.out.println("很抱歉,没有找到哦!");
}