Fork me on GitHub

jsp第一次作业

编写jsp页面,计算0-100之间所有素数之和

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 3 <html>
 4 <head>
 5 
 6 </head>
 7 <body>
 8     1-100之间的素数和为:
 9     <%
10     int sum = 0;
11     for (int i = 2; i <= 100; i++) {
12         for (int j = 2; j <= i; j++) {
13             if (i % j == 0 && i != j) {
14                 break;
15             }
16             if (i % j == 0 && i == j) {
17                 sum += i;
18             }
19         }
20     }
21     out.print(sum);
22 %>
23 </body>
24 </html>

 

 

 

posted @ 2021-03-04 10:47  世界丶已黑白  阅读(69)  评论(0编辑  收藏  举报