题解 | #编排字符串#

编排字符串

https://www.nowcoder.com/practice/42c0673f04b34f66ae236a1cb7995532?tpId=40&tqId=31014&rp=1&ru=/ta/kaoyan&qru=/ta/kaoyan&difficulty=&judgeStatus=&tags=/question-ranking

import java.util.Scanner;

import java.util.ArrayList;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<String> list = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            list.add(scanner.next());
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i&&j<=4; j++) {
                System.out.print(j + "=" + list.get(i - j) + " ");
            }
            System.out.println();
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务