Advertisement
FedchenkoIhor

cr10in8pr10Array

Apr 14th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. package com.javarush.test.level07.lesson04.task02;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. /* Массив из строчек в обратном порядке
  8. 1. Создать массив на 10 строчек.
  9. 2. Ввести с клавиатуры 8 строчек и сохранить их в массив.
  10. 3. Вывести содержимое всего массива (10 элементов) на экран в обратном порядке. Каждый элемент - с новой строки.
  11. */
  12.  
  13. public class Solution {
  14.     public static void main (String[] args) throws Exception {
  15.         String[] array = createArray (10);
  16.         printMirrorArray (initializeArray (array, 8));
  17.  
  18.  
  19.     }
  20.  
  21.     public static String[] createArray (int size) {
  22.         String[] array = new String[size];
  23.         return array;
  24.     }
  25.  
  26.     public static String[] initializeArray (String[] input, int count) throws IOException {
  27.         BufferedReader reader = new BufferedReader (new InputStreamReader (System.in));
  28.         if (count > 0 && count <= input.length) {
  29.             for (int i = 0; i < count; i++) {
  30.                 input[i] = reader.readLine ();
  31.             }
  32.         }
  33.  
  34.         return input;
  35.     }
  36.  
  37.     public static void printMirrorArray (String[] input){
  38.  
  39.         for (int i = 0; i < input.length; i++){
  40.             System.out.println (input[input.length-1-i]);
  41.         }
  42.     }
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement