當前位置:首頁 » 編程語言 » 100以內素數java

100以內素數java

發布時間: 2024-09-28 00:05:36

1. 用java求3到100的素數,初學者,求簡單的

public static void main(String[] args) {

int count = 0;

int sum = 0;

for (int i = 2; i <= 100; i++) {

boolean flag = false;

for (int j = 2; j <= i >> 1; j++) {

if (i % j == 0) {

flag = true;

break;

}

}

if (!flag) {

System.out.print(i + " ");

sum += i;

count++;

}

}

System.out.println();

System.out.println("1--100之間的素數(也稱質數)的個數 -->"+count);

System.out.println("1--100之間的素數(也稱質數)的個數之和 -->"+sum);

}

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:542
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:828
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:531
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:714
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:635
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:946
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:204
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:64
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:756
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:659