Write a program to initialize the given data in an array and find the minimum and
maximum values along with the sum of the given elements. (10)
Numbers : 2 5 4 1 3
Output : Minumum value : 1
Maximum value : 5
Sum of the elements : 15
Answers
Answered by
1
import java.util.Scanner;
public class arraytest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a []=new int[10];
System.out.println("Enter Elements");
for (int i= 0; i<10;i++)
a[i]= sc.nextInt();
int sum=0;
for (int i=0;i<10;i++)
{
for(int j=0;j<9-i;j++)
{
if(a[j]>a[j+1])
{int temp = a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
sum += a[i];
}
System.out.println("Smallest ="+a[0] +"and largest ="+a[9]) ;
System.out.println("Sum ="+sum) ;
}
}
Similar questions