0% found this document useful (0 votes)
3 views

java mean median

Uploaded by

fojimaw327
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

java mean median

Uploaded by

fojimaw327
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;
public class Main
{
public static void main(String[] args)
{
int i,j,sum=0;
Scanner sc= new Scanner(System.in);

System.out.println("Enter the number of elements in array");


int n=sc.nextInt();

int a[]=new int[n];


System.out.println("Enter the array elements");
for(i=0;i<n;i++)
{
int num=sc.nextInt();
a[i]=num;
}

for(i=0;i<n-1;i++)
{
int flag=0;
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
flag=1;
}
}
if(flag==0);
break;
}

System.out.println();
System.out.println("the elements after sorting are:");
for(int value: a)
{
System.out.println(value+" ");
}

for(j=0;j<n;j++)
{
sum=sum+a[j];
}
double mean=sum/n;

/*
{
int median;
int middle = a[j].length/2;
if (a[j].length%2!=0)
{
median=a[middle];
}
else
{
median=(a[middle-1] + a[middle]) / 2.0;
}
*/
System.out.println("STATISTICAL INFORMATION");
System.out.println("------------------------------------------");
System.out.println("arithmetic mean "+mean);
//System.out.println("median "+median);

}
}

You might also like