CoineTre

JF-LabArrays04.Reverse Array String

Jan 18th, 2021 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Lab4ReverseArrayStrings {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String[] arrInput = scanner.nextLine().split(" ");
  7.         for (int i = 0; i < arrInput.length / 2 ; i++) {
  8.             int contraIndex = arrInput.length -1-i;
  9.             String temp = arrInput[i];
  10.             arrInput[i] = arrInput[contraIndex];
  11.             arrInput[contraIndex] = temp;
  12.         }
  13.         System.out.println(String.join(" ",arrInput));
  14.  
  15.     }
  16. }
  17. /* Write a program to read an array of strings, reverse it and print its elements.
  18.  The input consists of a sequence of space separated strings. Print the output on a single line (space separated).
  19. */
Add Comment
Please, Sign In to add comment