作者gulie (dark frame master)
标题Re: [问题] 如何改为不重复质数,但每行5组列印???
时间Mon Sep 18 09:45:25 2023
用COUNT 累计到五就 换行 归0
public class practice_1 {
public static void main(String[] args) {
int numA = 1;
int count=0;
int a, b, c,d;
for (a = 2; a <= 100; a++) {
for (b = 2; b < a; b++) {
if (a % b == 0)
break; }
if (b >= a) {
count++;
System.out.print(a);
if ( count ==5) {
System.out.println();
count = 0;
}
}
}
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 125.228.190.168 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/java/M.1695001533.A.F16.html