首页 > 其他 > 详细

List Filtering the list

时间:2020-09-27 16:11:30      阅读:46      评论:0      收藏:0      [点我收藏+]

Write a program that reads the list of integer numbers separated by spaces from the standard input and then remove all numbers with even indexes (0, 2, 4, and so on).

After that, the program should output the resulting sequence in the reverse order.

Report a typo
Sample Input 1:

1 2 3 4 5 6 7
Sample Output 1:

6 4 2
Sample Input 2:

1 2
Sample Output 2:

2
Sample Input 3:

7 6 -5 -4 -3 2 1
Sample Output 3:

2 -4 6

import java.util.List;
import java.util.Scanner;

class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);

        List<String> out = List.of(sc.nextLine().split("\\s+"));

        for (int i = out.size() - 1; i > -1; i--) {
            if (i % 2 != 0) {
                System.out.printf("%s ", out.get(i));
            }
        }
    }
}

List Filtering the list

原文:https://www.cnblogs.com/longlong6296/p/13739184.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!