EChebanenko

Untitled

Sep 4th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Lesson7HW2_14 {
  6.  
  7.     public static void main(String args[]) {
  8.  
  9.         consoleOutput("Введите строку: \"Привет меня зовут Максим\"");
  10.         String str = getInputString();
  11.         String[] wordsArr = arrayFromStr(str);
  12.         String[] revertArr = revertArray(wordsArr);
  13.         printArray(revertArr);
  14.     }
  15.  
  16.     public static void consoleOutput(String str) {
  17.         System.out.println(str);
  18.     }
  19.  
  20.     public static String getInputString() {
  21.         Scanner scanner = new Scanner(System.in);
  22.         String rawStr = scanner.nextLine();
  23.         return rawStr;
  24.     }
  25.  
  26.     public static String[] arrayFromStr(String str) {
  27.         String[] words = str.trim().split(" ");
  28.         return words;
  29.     }
  30.  
  31.     public static String[] revertArray(String[] words) {
  32.         String[] arr = words;
  33.  
  34.         String temp = null;
  35.         int count = arr.length;
  36.         for (int i = 0; i < count / 2; i++) {
  37.             temp = arr[count - i - 1];
  38.             arr[count - i - 1] = arr[i];
  39.             arr[i] = temp;
  40.         }
  41.         return arr;
  42.     }
  43.  
  44.     public static void printArray(String[] words) {
  45.         for (String word : words) {
  46.             System.out.print(word + " ");
  47.         }
  48.     }
  49. }
Add Comment
Please, Sign In to add comment