The JSP code implements the pyramid of inversion example
- 2020-04-01 02:59:18
- OfStack
Implement the pyramid shown in the figure in the JSP,
< img border = 0 SRC = "/ / files.jb51.net/file_images/article/201402/2014225162852024.jpg" >
The code is as follows:
The general idea is as follows:
1. Draw the first 5 lines. Because I + Spaces = total number of lines, so the number of Spaces in the first row is the total number of lines - I (line number), and then I draw *, the number of * =2 times I -11;
2. Draw the remaining four lines. Because the number of Spaces = the number of rows I, the number of * =(total rows - I)*2+1
<%
for(int i=1;i<6;i++){
for(int j=0;j<5-i;j++){
str +=" ";
}
for(int j=0;j<2*i-1;j++){
str +="*";
}
str += "<br>";
}
for(int i=1;i<5;i++){
for(int j=1;j<i+1;j++){
str +="&";
}
for(int k=0;k<2*(4-i)+1;k++){
str +="*";
}
str += "<br>";
}
%>
<%=str%>