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. int[] vet = { 7, -4, 10, 8, 2, 5 };
  13.  
  14. System.out.println("Array sem ordenacao:");
  15.  
  16. for (int n : vet) {
  17. System.out.print(n + " ");
  18. }
  19. System.out.println();
  20.  
  21. for(int i=0;i<vet.length;i++)
  22. {
  23. vet[i]=-vet[i];
  24. }
  25.  
  26. Arrays.sort(vet);
  27.  
  28. for(int i=0;i<vet.length;i++)
  29. {
  30. vet[i]=-vet[i];
  31. }
  32.  
  33. System.out.println("Array em ordem decrescente:");
  34.  
  35. for (int n : vet) {
  36. System.out.print(n + " ");
  37. }
  38. System.out.println();
  39. }
  40. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Array sem ordenacao:
7 -4 10 8 2 5 
Array em ordem decrescente:
10 8 7 5 2 -4