Advertisement
Dido09

ReverseArrays

Jan 2nd, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ReverseArrays {
  4.  
  5. static void revArrays(String[] arr) {
  6. for(int i = 0; i < arr.length / 2; i++){
  7. String temp = arr[i];
  8. arr[i] = arr[arr.length - 1 - i];
  9. arr[arr.length - 1 - i] = temp;
  10. }
  11. }
  12.  
  13. public static void main(String[] args) {
  14. Scanner scan = new Scanner(System.in);
  15. String value = scan.nextLine();
  16. String[] arr = value.split(" ");
  17. revArrays(arr);
  18. for (int i = 0; i < arr.length; i++) {
  19. System.out.print(arr[i] + " ");
  20. }
  21.  
  22. }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement