zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    SQL SERVER DBCC命令参考
    Sqlserver 死锁问题
    收集面试题目DB
    收集面试题目Net
    [转]Virtual PC 2007虚拟机上安装Ubuntu 8.10桌面版
    Tcl/tk基础-2
    【转】内存详解
    [转]C# P2P与NAT技术之二
    泛型跟KeyNotFoundException
    用InstallAware 9制作BDE安装程序
  • 原文地址:https://www.cnblogs.com/menfanbo/p/14475790.html
Copyright © 2011-2022 走看看