ya_zay4eg

level07.lesson09.task05

Dec 12th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. package com.javarush.test.level07.lesson09.task05;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5. import java.util.ArrayList;
  6.  
  7. /* Удвой слова
  8. 1. Введи с клавиатуры 10 слов в список строк.
  9. 2. Метод doubleValues должен удваивать слова по принципу a,b,c -> a,a,b,b,c,c.
  10. 3. Используя цикл for выведи результат на экран, каждое значение с новой строки.
  11. */
  12.  
  13. public class Solution
  14. {
  15.     public static void main(String[] args) throws Exception {
  16.         //read strings and init ArrayList list here - считать строки с консоли и объявить ArrayList list тут
  17.         ArrayList <String> list = new ArrayList<String>();
  18.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  19.  
  20.         for (int i = 0; i<10; i++) {
  21.             list.add(reader.readLine());
  22.         }
  23.  
  24.         ArrayList<String> result = doubleValues(list);
  25.  
  26.  
  27.         //print result - вывести на экран result
  28.        // System.out.println(result);
  29.         for (int i = 0; i<result.size(); i++) {
  30.             System.out.println(result.get(i));
  31.         }
  32.  
  33.     }
  34.  
  35.     public static ArrayList<String> doubleValues(ArrayList<String> list) {//возвращает ArrayList
  36.         // add your code here - добавь код тут
  37.         ArrayList <String> newlist = new ArrayList<String>();
  38.         int b=0;
  39.         for (int a = list.size()-1; a >= 0; a--) {
  40.             newlist.add(b, list.get(a));
  41.             newlist.add(b, list.get(a));
  42.         }
  43.  
  44.         return newlist;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment