题解 | #挑7#
挑7
http://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b
思路:循环判断i是7的倍数,或者转成String后包含7,计数+1
import java.util.*; public class SelectSeven { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { int a = sc.nextInt(); int cnt = 0; for (int i = 1; i <= a; i++) { if (i % 7 == 0 || (i + "").contains("7")) { System.out.println(i); cnt++; } } System.out.println(cnt); } } }