Java Application | Calculates the median value

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@ryal·
0.000 HBD
Java Application | Calculates the median value
<h3> Source Code</h3>
>import java.util.*;
public class MinMaxDAC {
    public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		System.out.println("Enter number of elements");
		int n=sc.nextInt();
		int a[]=new int[n];
		System.out.println("Enter elements");
		for(int i=0;i < n;i++)
		a[i]=sc.nextInt();		
		int c=0,part=0, d, s;
		while(part < n)
		{
			part=part+3;
			c++;
		}
		part=0;
		int l=0,h=2;
		while(part < c)
		{
			System.out.println("The part of array is");
			for(int i= l; i <= h; i++)
				System.out.println(a[i] + "  ");
			System.out.println();
		System.out.println("Maximum of this part of array is");
			int v=a[l];
			for(int i=l;i <= h;i++)
				if(a[i] > v)
					v=a[i];
			System.out.println(v);
			System.out.println();
		System.out.println("Minimum of this part of array is");
			int v1=a[l];
			for(int i=l;i <= h;i++)
				if(a[i] < v1)
					v1=a[i];
			System.out.println(v1);
			System.out.println();
			part++;
			l=l+3;
			if((h+3) < n)
				h=h+3;
			else
				h=n-1;
		}
		d=s=a[0];
		for(int i=0;i < n;i++)
		{
			if(a[i] > d)
			d=a[i];
			if(a[i] < s)
			s=a[i];
		}
		System.out.println("Maximum element is:"+d);
		System.out.println();
		System.out.println("Minimum element is:"+s);
	}
}

<center><h3>Output Aplication</h3>
<center>https://steemitimages.com/DQmaZNpfRbkanc9Z9ww6huLX5wpWVn85HisaPLGmZXyQQ9h/Median%20Aplication.png</center>
***
<center><h3>FOLLOW ME: @ryal</h3></center>
***
👍 , , , , , , , , , , , , , , , , , , , ,