题解 | #牛牛的二三七整除#

牛牛的二三七整除

https://www.nowcoder.com/practice/b2cf0b791245436f8f0591ae9f4c664f

import java.util.Scanner;
import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            ArrayList<Integer> a = new ArrayList<Integer>();
            if (n % 2 == 0){
                a.add(2);
            }
            if (n % 3 == 0){
                a.add(3);
            }
            if (n % 7 == 0){
                a.add(7);
            }
            if(a.size() == 0){
                System.out.print("n");
            }
            else{
            Collections.sort(a);
             for(int i : a){
                System.out.print(i + " ");
             }
            }
        }
    }
}
            // int b = in.nextInt();
            // int[] a = new int[3];
            // if (n % 2 == 0){
            //     a[0] = 2;
            // }
            // if (n % 3 == 0){
            //     a[1] = 3;
            // }
            // if (n % 7 == 0){
            //     a[2] = 7;
            // }
            // for(int i = 0 ; i < a.length; i++){
            //     System.out.print(a[i] + " ");
            // }

全部评论

相关推荐

码农索隆:有点耳熟,你们是我教过最差的一届
点赞 评论 收藏
分享
星辰再现:裁员给校招生腾地方
点赞 评论 收藏
分享
一tiao酸菜鱼:秋招还没正式开始呢,就准备有结果了。。。。?
点赞 评论 收藏
分享
宇算唯航:目测实缴资本不超100W的小公司
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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