题解 | #牛牛的二三七整除#
牛牛的二三七整除
https://www.nowcoder.com/practice/b2cf0b791245436f8f0591ae9f4c664f
import java.util.Arrays; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = in.nextInt(); /* 利用sort排序 int a[] = new int[3]; a[0] = num%2==0?2:0; a[1] = num%3==0?3:0; a[2] = num%7==0?7:0; Arrays.sort(a); int sum =0 ; for(int i=0;i<a.length;i++){ if(a[i]!=0){ System.out.printf("%d ",a[i]); } sum+=a[i]; } if(sum==0){ System.out.println("n"); } */ if( num%2!=0 && num%3!=0 && num%7!=0){ System.out.print("n"); }else{ if(num%2==0){ System.out.print(2+" "); } if(num%3==0){ System.out.print(3+" "); } if(num%7==0){ System.out.print(7+" "); } } } }