# Field Manual for Hackers

## Java | Find the minimum and maximum set of values. Hint : calculate median

1. import java.util.Scanner;
class SetArray
{
public static void main(String args[])
{
int mid;
Scanner scan=new Scanner(System.in);
System.out.println("How many number you want to add");
int n=scan.nextInt();
int ar[]=new int[n];
System.out.println("Enter Numbers");
for (int i=0;i<n;i++)
{
ar[i]=scan.nextInt();
}
mid=n/2;
System.out.print("Minimun Set ");
for (int i=0;i<mid;i++)
{
System.out.print(ar[i]+" ");
}
System.out.print("\n\nMaximun Set ");
for (int i=mid;i<n;i++)
{
System.out.print(ar[i]+" ");
}

}
}

2. import java.util.Scanner;

class maxmin {
public static void main(String args[])
{
float temp;
Scanner scan=new Scanner(System.in);
System.out.println("How many number you want to add");
int n=scan.nextInt();
float ar[]=new float[n];
float median =0;
System.out.println("Enter elements in array");
for (int i=0;i<n;i++)
{
ar[i]=scan.nextFloat();
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(ar[i]<ar[j])
{
temp=ar[i];
ar[i]=ar[j];
ar[j]=temp;
}
}
}
System.out.println("New array after sorting ");
for (int i=0;i<n;i++)
{
System.out.print(ar[i]+" ");
}
if(n%2==0)
{
float sum = ar[n/2] + ar[(n/2)-1] ;
median = sum/2;
System.out.println( "The median is"+median);
}
else
{
System.out.println("The median is"+ar[n/2]);
}
for (int i=0;i<n;i++)
{
if(ar[i]<median)
{
System.out.print("minimum value "+(i+1)+" : ");
System.out.println(+ar[i] +" ");
}
else
{
System.out.println("maximum value "+(i+1)+" : "+ar[i] +" ");
}
}
}
}
OUTPUT:

How many number you want to add
6
Enter elements in array
12
32
53
123
125
43
New array after sorting
12.0 32.0 43.0 53.0 123.0 125.0 The median is48.0
minimum value 1 : 12.0
minimum value 2 : 32.0
minimum value 3 : 43.0
maximum value 4 : 53.0
maximum value 5 : 123.0
maximum value 6 : 125.0

3. import java.util.Scanner;
class D
{
public static void main(String args[])
{
Scanner obj=new Scanner(System.in);
int n;
System.out.println("Enter the value of n");
n=obj.nextInt();
int arr[]=new int[n];
int i,j;
System.out.println("Enter the array");
for(i=0;i<n;i++)
{
arr[i]=obj.nextInt();
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.println("The array after sorting is=");
for(i=0;i<n;i++)
{
System.out.println(arr[i]);
}
if(n%2==0)
{
System.out.println("The median is"+arr[(n/2)-1]+"and"+arr[n/2]);
}
else
{
System.out.println("The median is"+arr[n/2]);
}
for (int i=0;i<n;i++)
{
if(arr[i]<median)
{
System.out.print("minimum value "+(i+1)+" : ");
System.out.println(arr[i] +" ");
}
else
{
System.out.println("maximum value "+(i+1)+" : "arr[i] +" ");
}
}
}
}

4. import java.util.Scanner;
class Set
{
public static void main(String Args[])
{
int n,i,j;
int mid,temp;
System.out.println("How many numbers you want to enter?");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
int AR[]=new int[n];
System.out.println("enter the values");
for(i=0;iAR[j])
{
temp=AR[i];
AR[i]=AR[j];
AR[j]=temp;
}
}
}
System.out.println("sorting array:");
for(i=0;i<n;i++)
{
System.out.println(AR[i]+"");
}
mid=n/2;
System.out.println("minimum set of values are :");
for(i=0;i<mid;i++)
{
System.out.println(AR[i]+"");
}
System.out.println("maximum set of values are :");
for(i=mid;i<n;i++)
{
System.out.println(AR[i]+"");
}
}}

5. This comment has been removed by the author.

6. import java.util.Scanner;
class Sets{
public static void main(String ar[]){
Scanner obj=new Scanner(System.in);
int n,i,j,flag;
System.out.println("enter the value of n");
n=obj.nextInt();
int arr[]=new int[n];
for(i=0;iarr[j]){
flag=arr[i];
arr[i]=arr[j];
arr[j]=flag;
}
}
}
for(i=0;i<n;i++)
System.out.println(arr[i]);

System.out.println("this is the sorted array");
System.out.println("minimum set of values");
for(i=0;i<n/2;i++)
System.out.println(arr[i]);
System.out.println("maximum set of values");
for(i=n/2;i<n;i++)
System.out.println(arr[i]);

}

}

7. This comment has been removed by the author.

8. This comment has been removed by the author.

9. import java.util.Scanner;
class Minmax{
public static void main(String a[]){
int n,median,temp;
Scanner scan=new Scanner(System.in);
System.out.println("Enter the size:");
n=scan.nextInt();
int ar[]=new int[n];
System.out.println("Enter the values:");
for(int i=0;imedian){
System.out.println("The maximum set of values is:"+ar[i]);
}
}
}
}