作者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/m.aspx?n=bbs/java/M.1695001533.A.F16.html