Advertisement
UKTC162

ChangePositionArray

Dec 13th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ChangePositionArray {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner sc = new Scanner(System.in);
  7.  
  8.         int n = Integer.parseInt(sc.nextLine());
  9.         char temp = ' ';
  10.         char[] word = new char[n];
  11.         for (int i = 0; i < word.length; i++) {
  12.             word[i] = sc.next().charAt(0);
  13.         }
  14.  
  15.         for (int i = 0; i < word.length - 1; i++) {
  16.             temp = word[i];
  17.             word[i] = word[word.length - 1 - i];
  18.             word[word.length - 1 - i] = temp;
  19.             if (i == word.length / 2 - 1) {
  20.                 break;
  21.             }
  22.         }
  23.  
  24.         System.out.println(word);
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement