Class Shuzu4
{
public static void Main (string[] args)
{
Int[] Arr=new int[]{12,34,55,22,54,3,2,2,-9,0,-89};
Maximum Value
int max=arr[0];
for (int i=0;i<arr.length;i++) {
if (Max<=arr[i]) {
Max=arr[i];
}
}
SYSTEM.OUT.PRINTLN ("Maximum value is" +max);
Minimum value
int min=arr[0];
for (int i=0;i<arr.length;i++) {
if (Min>=arr[i]) {
Min=arr[i];
}
}
SYSTEM.OUT.PRINTLN ("Minimum value is" +min);
Sum
int sum=0;
for (int i=0;i<arr.length;i++) {
Sum+=arr[i];
}
System.out.println ("sum is" +sum);
Average
Double ave=0;
Ave=sum/arr.length;
System.out.println ("average is" +ave);
Copy
Int[] Arr1=new int[arr.length];
for (int i=0;i<arr1.length;i++) {
Arr1[i]=arr[i];
}
element inversion in an array
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;
}
Or
for (int x=0,y=arr.length-1;x<y;x++,y--) {
int temp=arr[x];
Arr[x]=arr[y];
Arr[y]=temp;
}
Traverse
for (int i=0;i<arr1.length;i++) {
System.out.println (Arr1[i]);
}
}
}
"Song Hongkang Program thought learning Diary 4" Array simple operation