Advertisement
FedchenkoIhor

sortList

May 16th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package com.javarush.test.level0.lesson1.home0;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. /* Переставить M первых строк в конец списка
  10. Ввести с клавиатуры 2 числа N  и M.
  11. Ввести N строк и заполнить ими список.
  12. Переставить M первых строк в конец списка.
  13. Вывести список на экран, каждое значение с новой строки.
  14. */
  15.  
  16. public class Solution {
  17.     public static void main(String[] args) throws IOException {
  18.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  19.  
  20.         int N = Integer.parseInt(reader.readLine());
  21.         int M = Integer.parseInt(reader.readLine());
  22.         List list = new ArrayList<String>();
  23.  
  24.         for (int i = 0; i < N; i++) {
  25.             list.add(reader.readLine());
  26.         }
  27.         printList(sortList(list,M));
  28.     }
  29.  
  30.     public static List sortList(List input, int amountToReplace) {
  31.         for (int i = 0; i < amountToReplace; i++){
  32.             input.add(input.get(0));
  33.             input.remove(0);
  34.         }
  35.         return input;
  36.     }
  37.  
  38.     public static void printList (List input){
  39.         for (Object elementList : input){
  40.             System.out.println(elementList);
  41.         }
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement