垂直输出字符串数组
输入字符串,垂直输出,例如:输入“wellcome”“to”“guangzhou”
输出: u
e o
m h
o z
c g
l n
l a
e o u
w t g
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> </head> <body> <p>look:</p> <script type="text/javascript"> function layOut(s){ var maxLength = 0; var innerHtml = ""; var p = document.getElementsByTagName("p"); for(var i = 0; i < s.length; i++){ if(s[i].length > maxLength){ maxLength = s[i].length; } } for(var i = maxLength-1; i >= 0; i--){ for(var j = 0; j < s.length; j++){ if(s[j].length > i){ innerHtml += s[j][i]; } else{ innerHtml += " "; } } innerHtml = innerHtml + "<br/>"; } p[0].innerHTML = innerHtml; } layOut(new Array("welcome","to","guangzhou")); </script> </body> </html>