标签:dma ota 最小 code test rgs ++ tin util
1. 创建的对象,没有显示的赋给一个变量名,即为匿名对象。
2. 匿名对象只能调用一次
class Phone {
private int price;
public void sendMail() {
System.out.println("send your mail~");
}
}
class PhoneMall {
public void show(Phone phone) {
phone.sendMail();
}
}
class PhoneTest {
public static void main(String[] args) {
PhoneMall mall = new PhoneMall();
mall.show(new Phone());
}
}
public class ArrayUtils {
//求最大值
public int getMax(int[] arr) {
int maxValue = arr[0];
for (int i = 0; i < arr.length; i++) {
if (maxValue < arr[i]) {
maxValue = arr[i];
}
}
return maxValue;
}
//求最小值
public int getMin(int[] arr) {
int minValue = arr[0];
for (int i = 0; i < arr.length; i++) {
if (minValue > arr[i]) {
minValue = arr[i];
}
}
return minValue;
}
//求总和
public int getSum(int[] arr) {
int total = 0;
for (int i = 0; i < arr.length; i++) {
total += arr[i];
}
return total;
}
//求平均值
public int getAvg(int[] arr) {
int total = getSum(arr);
int avge = total / arr.length;
return avge;
}
//翻转数组
public void reverse(int[] arr) {
for (int i = 0; i < arr.length / 2; i++) {
int temp = arr[i];
arr[i] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}
}
//复制数组
public int[] copy(int[] arr) {
int[] arrTemp = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
arrTemp[i] = arr[i];
}
return arrTemp;
}
//数组排序
public int[] sort(int[] arr) {
return null;
}
//遍历数组
public void print(int[] arr) {
}
//查找元素
public int getIndex(int[] arr, int dest) {
for (int i = 0; i < arr.length; i++) {
if (dest == arr[i]) {
return i;
}
}
return -1;
}
}
public class ArrayTest {
public static void main(String[] args) {
ArrayUtils util = new ArrayUtils();
int[] arr = new int[]{10, 23, 19, 18, -14, 93, 82, 93, 5};
int max = util.getMax(arr);
int total = util.getSum(arr);
int avg = util.getAvg(arr);
//util.reverse(arr);
int[] arr1 = util.copy(arr);
int cell = util.getIndex(arr, 115);
System.out.println(cell);
}
}
标签:dma ota 最小 code test rgs ++ tin util
原文地址:https://www.cnblogs.com/hq82/p/12080261.html