/* Date:29/10/2008 Author: Deepak Majeti report bugs to: mdeepak@cse.iitk.ac.in */ // 2. Create an array A with enteries randomly selected from range 0 to 10000. // The length of array A is provided from command line. Print the array on the monitor. We // say that there is a local minima at index i, if A[i] is less than A[i − 1] as well as A[i + 1]. // Print // (a) indices of all local minima // (b) the total count of all the local minima. class LocalMinima{ public static void main(String args[]){ int array[]=null; int arraySize=0; int before=0; int after=0; int count=0; try{ arraySize=Integer.parseInt(args[0]); }catch(Exception e){ System.out.println("Please enter and integer(array size) as argument"); System.exit(0); } array=new int[arraySize]; //fill the array randomly using numbers between 0-99 and print them System.out.println("Array being generated. The "+ arraySize+" numbers are:"); for(int i=0;i array[i] && array[i] < after){ System.out.print(i+", "); count++; } before=array[i]; } System.out.println("\n\nThe total number of indices having local minima are:"+count); } }