Advertisement
JVFabia

Clase 1 Colecciones

Sep 23rd, 2020
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package org.forge;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9. // write your code here
  10.  
  11. List<Double> randoms = new ArrayList<Double>();
  12.  
  13. for (int i = 0; i < 3; i++) {
  14. randoms.add(Math.random());
  15. }
  16. System.out.println("Lista inicial \n" + randoms + "");
  17. //System.out.println(randoms.size()-1);
  18.  
  19. double tmp = randoms.get(0);
  20. randoms.set(0, randoms.get((randoms.size() - 1)));
  21. randoms.set(randoms.size() - 1, tmp);
  22. System.out.println("lista modificada \n" + randoms);
  23.  
  24. double min = 1;
  25. double max = 0;
  26. for (double x : randoms) {
  27. if (x > max) max = x;
  28. if (x < min) min = x;
  29. }
  30. int pmax = randoms.indexOf(max);
  31. int pmin = randoms.indexOf(min);
  32.  
  33. randoms.set(pmax,min);
  34. randoms.set(pmin, max);
  35.  
  36. System.out.println("lista max min \n" +randoms);
  37.  
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement