Created
July 31, 2015 14:09
-
-
Save vitaliiSmokov/24d724ba4b206b49f8bc to your computer and use it in GitHub Desktop.
Удвой слова
1. Введи с клавиатуры 10 слов в список строк.
2. Метод doubleValues должен удваивать слова по принципу a,b,c -> a,a,b,b,c,c.
3. Используя цикл for выведи результат на экран, каждое значение с новой строки.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level07.lesson09.task05; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
/* Удвой слова | |
1. Введи с клавиатуры 10 слов в список строк. | |
2. Метод doubleValues должен удваивать слова по принципу a,b,c -> a,a,b,b,c,c. | |
3. Используя цикл for выведи результат на экран, каждое значение с новой строки. | |
*/ | |
public class Solution | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
ArrayList<String> list = new ArrayList<String>(); | |
//Считать строки с консоли и объявить ArrayList list тут | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
for (int i = 0; i < 10; i++) | |
list.add(reader.readLine()); | |
//System.out.println("Array: " + list.toString()); | |
ArrayList<String> result = doubleValues(list); | |
//Вывести на экран result | |
for (int i = 0; i < result.size(); i++) | |
System.out.println(result.get(i)); | |
//System.out.println("doubleArray: " + result.toString()); | |
} | |
public static ArrayList<String> doubleValues(ArrayList<String> list) | |
{ | |
//напишите тут ваш код | |
for (int i = 0; i < list.size();) { | |
list.add( i, list.get(i)); | |
i += 2; | |
} | |
return list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment