import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class ArrayApp {
public static void main(String[] args)
{
ArrayList
Scanner input = new Scanner(System.in);
System.out.println("Enter first number:");
int num1 = input.nextInt();
System.out.println("Enter second number:");
int num2 = input.nextInt();
System.out.println("Enter third number:");
int num3 = input.nextInt();
System.out.println("Enter fourth number:");
int num4 = input.nextInt();
System.out.println("Enter fifth number:");
int num5 = input.nextInt();
System.out.println("Enter sixth number:");
int num6 = input.nextInt();
System.out.println("Enter seventh number:");
int num7 = input.nextInt();
System.out.println("Enter eight number:");
int num8 = input.nextInt();
System.out.println("Enter nineth number:");
int num9 = input.nextInt();
System.out.println("Enter last number:");
int num0 = input.nextInt();
myArr.add(num1);
myArr.add(num2);
myArr.add(num3);
myArr.add(num4);
myArr.add(num5);
myArr.add(num6);
myArr.add(num7);
myArr.add(num8);
myArr.add(num9);
myArr.add(num0);
Object arr[] = myArr.toArray();
System.out.println("myArray is : "+myArr);
Collections.sort(myArr);
System.out.println("Sort Array is : "+myArr);
double sum, average;
sum =0;
for (int i = 0; i < arr.length; i++) {
sum+=((Integer)arr[i]).intValue();
}
System.out.println("Sum is :" + sum);
average = sum / arr.length;
System.out.println("Average is :" + average);
System.out.println("Max Number is :" + getMaxValue(arr));
System.out.println("Min Number is :" + getMinValue(arr));
}
public static int getMaxValue(Object arr[] ){
int maxValue = ((Integer)arr[0]).intValue();
for(int i=1;i
if(((Integer)arr[i]).intValue() > maxValue){
maxValue = ((Integer)arr[i]).intValue();
}
}
return maxValue;
}
public static int getMinValue(Object arr[] ){
int minValue = ((Integer)arr[0]).intValue();
for(int i=1;i
if(((Integer)arr[i]).intValue() < minValue){
minValue = ((Integer)arr[i]).intValue();
}
}
return minValue;
}
}
No comments:
Post a Comment