Help with an Array program please?
I have to write this Array program a long certain specifications but I am currently stuck, if someone can help that would be great. What I have so far is posted below. What Still need to do is:
-Write a function called selsort that takes an integer array, which is guaranteed to have only positive integers, and sorts it in descending order.
-Inside selsort, create a new array. Call getMaxIndex repeatedly, and insert the max element into the new array. Set that element in the original array to such a number so that it does not come up as a max number anymore.
- and some other stuff with BagOfFruit, but I can easily finish that myself, i just need help with the above two instructions
If you haven't noticed I am no good with Arrays:o
Sorry
Quote:
class BagOfFruit
{
public int numberOfApples;
public int numberOfOranges;
}
public class Lab9
{
public static int[] getFibonacci(int Size)
{
int[] arr = new int[Size];
arr[0] = 1;
arr[1] = 1;
for(int i = 2; i < Size; i++)
{
arr[i] = arr[i-1] + arr[i - 2];
}
return arr;
}
public static int getMaxIndex(int[] arr)
{
int maxIndex = 0;
for(int i = 1; i < arr.length; i++)
{
if ( arr[i] > arr[maxIndex] ) maxIndex = i;
}
return maxIndex;
}
public static int selsort(int[] arr)
{
}
public static void main(String[] args)
{
int[] a = getFibonacci(10);
System.out.println(java.util.Arrays.toString(a));
int[] BagOfFruit = new int[3];
}
}