fork download
  1. import java.util.Scanner;
  2.  
  3. class HelloWorld {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int a = sc.nextInt();
  7. int[] v = new int[a];
  8. for (int i = 0; i < a; i++) {
  9. v[i] = sc.nextInt();
  10. }
  11. funcao(v);
  12. for (int i = 0; i < a; i++) {
  13. System.out.println(v[i]);
  14. }
  15. }
  16.  
  17. static void funcao(int[] v) {
  18. for (int j = 1; j < v.length; j++) {
  19. for (int i = 1; i < v.length; i++) {
  20. if (v[i] < v[i - 1]) {
  21. int temp = v[i];
  22. v[i] = v[i - 1];
  23. v[i - 1] = temp;
  24. }
  25. }
  26. }
  27. }
  28. }
Success #stdin #stdout 0.06s 711680KB
stdin
5
3
2
5
1
4
stdout
1
2
3
4
5