zoukankan      html  css  js  c++  java
  • JSP求和计算

    已知两个数的值,如何求和并输出?

    <%@ page language="java" import="java.util.*,java.text.*" contentType="text/html;charset=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>求和</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>
      <!-- 两个数的求和计算 -->
      <%
      int numA=4;
      int numB=5;
      int result=numA+numB;
       %>
       两个数的和是<%=result %>
      </body>
    </html>

     封装成函数

    <%@ page language="java" import="java.util.*,java.text.*" contentType="text/html;charset=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>求和</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">
        -->
        
        <%!
        //计算两个数和的算法
        int computeNum(int num1,int num2){
        return num1+num2;}
        %>
      </head>
      
      <body>
      <!-- 两个数的求和计算 -->
       两个数的和是<%=computeNum(5,8) %>
      </body>
    </html>
  • 相关阅读:
    软件工程第二次作业
    软件工程第一次作业
    细说GitHub分支策略和工作流
    第二次结对作业 四则运算生成器
    第一次结对作业
    软件工程第三次作业
    软件工程第二次作业
    软件工程第一次作业
    人工智能第一次作业
    人工智能第二次作业 书上69页作业
  • 原文地址:https://www.cnblogs.com/Yimi/p/8018091.html
Copyright © 2011-2022 走看看