diff --git a/Ranjithmanju b/Ranjithmanju new file mode 100644 index 0000000..7358a82 --- /dev/null +++ b/Ranjithmanju @@ -0,0 +1,55 @@ +package goodie; + +import java.util.Arrays; +import java.util.Scanner; + +public class employ { + + + + public class student { + static int minidifference (int array[],int N,int M) + { + int result= Integer.MAX_VALUE; + Arrays.sort(array); + for(int i=0;i<=N-M;i++) + result=Math.min(result, array[i+M-1]-array[i]); + return result; + + } + + static int findelements (int res, int array[],int N,int M) + { + + int result= Integer.MAX_VALUE; + for(int i=0;i<=N-M;i++) + { result=Math.min(result, array[i+M-1]-array[i]); + if (res==result) + return i; + } + return 0; + + } + public static void main(String[] args) + { + int array[]= {7980,22349,999,2799,229900,11101,9999,2195,9800,4999}; + String things[]= {"MI Band: 999","Sandwich Toaster:2195","cult pass:2799","Scale: 4999","Fitbit Plus: 7980","Microwave Oven: 9800","Alexa: 9999","Digital Camera: 11101","IPods: 22349","Macbook Pro: 229900"}; + int N= array.length; + System.out.println("enter the emplpoyees"); + + Scanner s=new Scanner(System.in); + + int M=s.nextInt(); + int result=minidifference (array,N,M); + System.out.println("Number of Employees :" +M); + + int startindex=findelements(result,array,N,M); + System.out.println("the goodies are selected distributionare"); + + for(int i=startindex ; i<=startindex+M; i++) + System.out.println(things[i]); + System.out.println('\n'); + System.out.println("difference between the chosen goodie with highest price and the lowest price" +result); + } + } +}