{ for(int i=0;i<arr.length;i++) public void doubler(int [ ] brr) S.O.P(arr[i]); { } for(int i=0; i<brr.length; i++) } brr[i]=brr[i]*2; } } class Test { public static void main(String [ ] args) { int [] arr={10,20,30,40,50}; Demo d=new Demo( ); Returning Array Reference class Demo { public int[ ] createArray(int n) { int [ ] brr=new int [n]; return brr; } } class Test { public static void main(String [ ] args) { Demo d=new Demo( ); int [ ] arr=d.createArray(5); System.out.println(“Length of array is ”+arr.length); } } Practice
• WAP to declare an integer array of 10 elements and
ask the user to input values in it. Now again ask the user to input another number and pass the array and number to a method called search. This method should be defined in class called ArraySearch. The method should return all the positions where the number is occurring. Assuming that the number will occur maximum 5 times.
• Design another method in the same class called
count() which should return total number of elements in the array which are greater than the number passed, smaller than the number passed and equal to the number passed. End Of Lecture 16