1

In simple... This program takes all number listed in array and first finds all numbers that can be divided by for evenly. Second it will take that array and sort the number in descending order

I am having trouble sorting the array in descending order. When I use the Arrays.sort(dividend, Collections.reverseOrder()); Netbeans keeps saying "no subtitle method found".

import java.util.*;



//This program will take all numbers in the array and First, find all the 
//numbers that are divisible by 4 and then sorts in descending order.

class ArrayFun 

{
 public static void main(String[] args)
{

    //Declaring Variables
    int[] dividend ={100,552,400,111,452,414,600,444,800};



    //Starting While Loop with nested if statement
    for(int i=0; i < dividend.length; i++)
    {     
       //Nested if statement
       if (dividend[i]%4 == 0)
       {
           System.out.println("This number '" +dividend [i]+ "' is divisble by 4.\n");

       }

    }

       //Sorts Array from highest number to lowest
       // This is the area that I am having programs.
       Arrays.sort(dividend, Collections.reverseOrder());

}

}

Thanks for any help!

Garbox
  • 5
  • 5

1 Answers1

3

Collections.reverseOrder() is a Comparator<Object>, so you can't sort ints with it. In general, you can't create a comparator to sort primitives. A workaround would be to put your integers into an Integer[] and sort that array (in the same fashion as you're trying to sort the primitive array).

arshajii
  • 127,459
  • 24
  • 238
  • 287