打印九九乘法表_JSP练习

 下面代码一个是声明的方法,一个是JSP脚本方法

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%! //返回打印九九乘法表的HTML代码,通过表达式调用,在页面中显示
			String formula1="";
			String formulaTable(){
			for(int i=1;i<10;i++){
				for(int j=1;j<=i;j++){
					int product=i*j;
					formula1+=i+"*"+j+"="+product;
					formula1+=" ";
				}
				formula1+="<br/>";//插入换行标签,实现切换操作
			}
			return formula1;
		}
	%>
	<h1>打印九九乘法表</h1>
	<hr>
	<%=formulaTable() %>	
	<%!
		void formulaTable1(JspWriter out) throws Exception{
			for(int i=1;i<10;i++){
				
				for(int j=1;j<=i;j++){
					String formula="";
					int product=i*j;
					formula=i+"*"+j+"="+product;
					out.println(formula);
					out.println(" ");
				}
				
				out.println("<br/>");
			}
		}
	%>	
	<%formulaTable1(out);%>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_17107171/article/details/81235019
今日推荐