• 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>

  • 相关阅读:
    ps cs5 gif 动画 分解
    api 生成方法
    AVAYA 交换机
    jQuery操作input值
    CMM3 软件升级
    ehcache 使用 缓存:健值,页面,Hibernate,监控
    网络封包分析软件Wireshark
    Hacking Windows 7 SP 1 Using Java Signed Applet Social Engineering Code Execution
    以太网历史
    转:web应用开发的发展方向
  • 原文地址:https://www.cnblogs.com/menfanbo/p/14475790.html
Copyright © 2020-2023  润新知