• jsp第一次作业


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

    提示:素数:在一个大于1的自然数中,除了1和此整数自身外,不能被其他自然数整除的数

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path + "/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    </head>
    
    <body>
        求1-100的素数和
        <br>
        <%
            int sum = 0;
            int[] a = new int[100];
            for (int i = 0; i < a.length; i++) {
                a[i] = i;
            }
            for (int i = 2; i < a.length; i++) {
                boolean flag = true;
                for (int j = 2; j < a[i]; j++) {
                    if (a[i] % j == 0)
                        flag = false;
                }
                if (flag) {
                    sum += i;
                }
    
            }
        %>
        1-100之间的素数和是:
        <%=sum%>
    </body>
    </html>

     2.   编写jsp页面,计算1-100之间的所有偶数之和

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path + "/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    </head>
    
    <body>
        求1-100的偶数和
        <br>
        <%
            int sum = 0;
            int[] a = new int[101];
            for (int i = 0; i < a.length; i++) {
                a[i] = i;
            }
            for (int i = 0; i < a.length; i++) {
                if (a[i] % 2 == 0) {
                    sum += i;
                }
            }
        %>
        1-100之间的偶数和是:
        <%=sum%>
    </body>
    </html>

  • 相关阅读:
    爬取淘宝商品信息
    eclipse 搭建Robotium环境--apk 环境搭建
    android studio2.0 搭建Robotium环境--有被测源代码的情况下
    mysql 特殊语句
    电脑浏览器访问文件夹
    mindmanager 15 停止工作
    yum被lock Existing lock /var/run/yum.pid: another copy is running as pid 1580. Another app is currently holding the yum lock; waiting for it to exi
    jenkins安装及部署
    ant+jmeter
    charles抓包及篡改
  • 原文地址:https://www.cnblogs.com/menfanbo/p/14475790.html
Copyright © 2020-2023  润新知