您的位置:

用js代码写菱形(用c语言写菱形代码)

用js代码写菱形(用c语言写菱形代码)

更新:

本文目录一览:

JavaScript用for循环打印这个菱形。

function Printfile() {

    var num = prompt("请输入菱形的边长(单击确定之后会看到以*为单位长度组成的菱形)");

    for (var i = 1; i = num; i++) //决定输出的行数

    {

        for (var j = 1; j = num - i; j++) //决定每一行开头的空格数

        {

            document.write("nbsp");

        }

        for (var k = 1; k = 2 * i - 1; k++) //决定每一行的*数

        {

            document.write("*");

        }

        document.write("/br");

    }

    for (var i = 1; i = num - 1; i++) //决定输出的行数

    {

        for (var j = 1; j = i; j++) //决定每一行开头的空格数

        {

            document.write("nbsp");

        }

        for (var k = 1; k = 2 * num - 1 - 2 * i; k++) //决定每一行的*数

        {

            document.write("*");

        }

        document.write("/br");

    }

}

调用后让你输入边长,输入之后就会出现菱形。

调用代码:

Printfile();

用javascript解决下面问题

html

head

title New Document /title

/head

body

script type="text/javascript"

!--

var count=10;//可以随意取值,可以尝试一下额。

//三角形

function triangle(){

for(var i=1;i=count;i++){

var str="";

for(var j=count;j0;j--){

if(j=i){

str=str+"*";

}else{

str=str+"nbsp";

}

}

document.write(str+"/br");

}

}

//菱形

function diamond(){

var side=1;n=0;//作用是控制循环的加减

for(var i=1;i0;i+=2*side){

var str="";

for(var j=count;j0;j--){

if(j=count/2+i/2j=count/2-i/2){

str=str+"*";

}else{

str=str+"nbsp";

}

}

n++;

if(n=count/2){

side=-1;

}

document.write(str+"/br");

}

}

triangle();

diamond();

//document.writeln(str2);

//--

/script

/body

/html

怎么用js输出一个菱形

方法有很多,我用HTML5的canvas写一个,你直接copy然后创建一个HTML文件,用google浏览器或者火狐亦或是高版本的IE打开就可以看到了

!DOCTYPE html

html

head

meta charset="UTF-8"

title/title

style type="text/css"

body{

margin: 0;

padding: 0;

}

#myCanvas{

margin:200px 600px;

border:5px solid #9c9898

}

/style

script type="text/javascript"

window.onload = function(){

var canvas = document.getElementById("myCanvas");

var context = canvas.getContext("2d");

drawLine(context,250,10,490,250,20,"blue","round");

drawLine(context,490,250,250,490,20,"blue","round");

drawLine(context,250,490,10,250,20,"blue","round");

drawLine(context,10,250,250,10,20,"blue","round");

}

function drawLine(context,startX,startY,endX,endY,lineWidth,strokeStyle,lineCap){

context.beginPath();

context.moveTo(startX,startY);

context.lineTo(endX,endY);

context.lineWidth = lineWidth;

context.strokeStyle = strokeStyle;

context.lineCap = lineCap;

context.stroke();

}

/script

/head

body

canvas id="myCanvas" width="500" height="500"/canvas

/body

/html

用Javascript语言做菱形

代码如下,你要的菱形

HTML

HEAD

TITLE New Document /TITLE

script

function draw(){

var line = parseInt(document.getElementById("myvalue").value);

var lineTemp = line%2;

if(0==lineTemp){

alert("函数必须是奇数");

return;

}

lineTemp = parseInt(line/2);

alert("line="+line+" lineTemp="+lineTemp);

var strArr = new Array();

for(var i=0;ilineTemp;i++){

for(var j=0;jline;j++){

if(((j+i)==lineTemp)||((j-i)==lineTemp)){

strArr.push("*");

}else{

strArr.push(" ");

}

}

strArr.push("br");

}

for(var i=lineTemp;iline;i++){

for(var j=0;jline;j++){

if(((j+i)==3*lineTemp)||((i-j)==lineTemp)){

strArr.push("*");

}else{

strArr.push(" ");

}

}

strArr.push("br");

}

document.getElementById("mydiv").innerHTML = strArr.join('');

}

/script

/HEAD

BODY

请输入奇数:input type="text" value="3" id="myvalue"

input type="button" onclick="draw()" value="show"

div id="mydiv"/div

/BODY

/HTML

用java编写菱形

for(i=1;i=4;i++)

{

这个小的for是打印每一行前边的空格

for(j=1;j=4-i;j++)

System.out.print(" ");

这个是打印星星的

for(j=1;j=2*i-1;j++)

System.out.print("*");

这个是打印完一行的换行

System.out.println("");

}

下边的是一样的  只不过每一行的空格和星星数   和上边是翻过来的

for(i=1;i=3;i++)

{

for(j=1;j=i;j++)

System.out.print(" ");

for(j=1;j=7-2*i;j++)

System.out.print("*");

System.out.println("");

}

java.sql.SQLException: 无效的列索引

无效的列索引

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207)

atoracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:5328)

atoracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:5320)

at untitled5.addreader1.validID(addreader1.java:128)

at untitled5.addreader1.jButton1_actionPerformed(addreader1.java:97)

at untitled5.addreader1_jButton1_actionAdapter.actionPerformed(addreader1.java:175)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

代码:String driverName = "oracle.jdbc.OracleDriver";

Driver driver = (Driver) Class.forName(driverName).newInstance();

//连接数据库

Connection con = DriverManager.getConnection(

"jdbc:oracle:thin:@LONG:1521:orcl", "sysman", "tongfang");

PreparedStatement pstmt = con.prepareStatement(

" insert into reader values(?)");

pstmt.setString(1, str1);

pstmt.setString(2,str2);

pstmt.setString(3,str3);

pstmt.setString(4,str4);

ResultSet res = pstmt.executeQuery();

如何从页面上输入数字来打印菱形 js

外层for是循环行

内层的两个for是输出每行的空格和*

你出示的这句恰恰体现了用户输入的数字和行之间的关系。

自己写着简单,读别人的就不简单了。因为他没有注释。不扣它也罢。