Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.forge;
- import java.util.ArrayList;
- import java.util.List;
- public class Main {
- public static void main(String[] args) {
- // write your code here
- List<Double> randoms = new ArrayList<Double>();
- for (int i = 0; i < 3; i++) {
- randoms.add(Math.random());
- }
- System.out.println("Lista inicial \n" + randoms + "");
- //System.out.println(randoms.size()-1);
- double tmp = randoms.get(0);
- randoms.set(0, randoms.get((randoms.size() - 1)));
- randoms.set(randoms.size() - 1, tmp);
- System.out.println("lista modificada \n" + randoms);
- double min = 1;
- double max = 0;
- for (double x : randoms) {
- if (x > max) max = x;
- if (x < min) min = x;
- }
- int pmax = randoms.indexOf(max);
- int pmin = randoms.indexOf(min);
- randoms.set(pmax,min);
- randoms.set(pmin, max);
- System.out.println("lista max min \n" +randoms);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement