fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. LinkedList<Integer> list = new LinkedList<Integer>();
  13.  
  14. // populate the list
  15. list.add(0);
  16. list.add(-1);
  17. list.add(3);
  18. list.add(100);
  19. list.add(-70);
  20. list.add(-50);
  21.  
  22.  
  23. // comparing using natural ordering
  24. Collections.sort(Math.abs(list));
  25. System.out.println("Max val: " + list);
  26.  
  27. int size = list.size();
  28. System.out.println((list.get(size-1)));
  29. System.out.println((list.get(size-2)));
  30. System.out.println((list.get(size-3)));
  31.  
  32.  
  33. System.out.println(size);
  34. }
  35. }
Compilation error #stdin compilation error #stdout 0.04s 4386816KB
stdin
Standard input is empty
compilation info
Main.java:24: error: no suitable method found for abs(LinkedList<Integer>)
    Collections.sort(Math.abs(list));
                         ^
    method Math.abs(int) is not applicable
      (argument mismatch; LinkedList<Integer> cannot be converted to int)
    method Math.abs(long) is not applicable
      (argument mismatch; LinkedList<Integer> cannot be converted to long)
    method Math.abs(float) is not applicable
      (argument mismatch; LinkedList<Integer> cannot be converted to float)
    method Math.abs(double) is not applicable
      (argument mismatch; LinkedList<Integer> cannot be converted to double)
1 error
stdout
Standard output is empty