WallHero

TP04E04 MainClass

Oct 30th, 2020 (edited)
686
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class PuntoCuatro {
  4.     public static void main(String[] args) {
  5.         new PuntoCuatro().run();
  6.     }
  7.     Scanner scanner = new Scanner(System.in);
  8.     void run()
  9.     {
  10.         SimpleLinkedList<Integer> numberList = chargeOriginalList(getRandomIntBetweenRange(2, 1000));
  11.         SimpleLinkedList<Integer> arrayWithDouble = obtainDoubleOfMultipleTen((SimpleLinkedListIterator<Integer>) numberList.iterator());
  12.  
  13.         SimpleLinkedListIterator<Integer> beginOfDoubleOfMultipleTen = (SimpleLinkedListIterator<Integer>) arrayWithDouble.iterator();
  14.         System.out.print("Lista original:[");
  15.         showList((SimpleLinkedListIterator<Integer>) numberList.iterator());
  16.         System.out.print("Lista de duplos divisibles por 2 y 5 (┬┐mejor 10?): [");
  17.        
  18.         showList(beginOfDoubleOfMultipleTen);
  19.        
  20.     }
  21.     void showList(SimpleLinkedListIterator<Integer> begin)
  22.     {
  23.         while(begin.hasNext())
  24.         {
  25.             System.out.print(begin.next() + ((begin.hasNext()) ? "," : "]\n" ));
  26.         }
  27.     }
  28.    
  29.     SimpleLinkedList<Integer> chargeOriginalList(int n)
  30.     {
  31.         SimpleLinkedList<Integer> ret = new SimpleLinkedList<Integer>();
  32.         while(n-- > 0) ret.addLast(getRandomIntBetweenRange(1, 1e9+7));
  33.         return ret;
  34.     }
  35.     int getRandomIntBetweenRange(double min, double max){
  36.         int x = (int) ((int)(Math.random()*((max-min)+1))+min);
  37.         return x;
  38.     }
  39.     SimpleLinkedList<Integer> obtainDoubleOfMultipleTen(SimpleLinkedListIterator<Integer> begin)
  40.     {
  41.         SimpleLinkedList<Integer> ret = new SimpleLinkedList<Integer>();
  42.  
  43.         while(begin.hasNext())
  44.         {
  45.             int pivoteValue = begin.next();
  46.             if(pivoteValue % 10 == 0) ret.addLast(pivoteValue*2);
  47.         }
  48.         return ret;
  49.     }
  50. }
  51.  
RAW Paste Data