Advertisement
Kancho

Methot_Reversed_Array

Mar 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Reversed_Print {
  5. public static void main(String[] args) {
  6.  
  7. Scanner sc = new Scanner(System.in);
  8. System.out.print("Enter numbers");
  9.  
  10. String input = sc.nextLine();
  11. int []numbers = readArrayFromString(input);
  12. for (int i = numbers.length -1; i >=0 ; i--) {
  13. System.out.print(numbers[i] + ", ".trim());
  14.  
  15. }
  16.  
  17. }
  18. public static int[] readArrayFromString(String input){
  19. return Arrays.stream(input.split("\\s+"))
  20. .mapToInt(Integer::parseInt)
  21. .toArray();
  22. }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement