快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

用java代码写一个菱形 用java代码写一个菱形图案

如何用java编写用 "*"输出菱形?

参考下面主要代码:

网站建设哪家好,找成都创新互联公司!专注于网页设计、网站建设、微信开发、小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了相城免费建站欢迎大家使用!

public static void draw()

{

int n=10;

for(int i=1;i=n;i++)//控制行数

{

for(int k=n-1;k=i;k--)//打印空格

{

System.out.print(" ");

}

for(int j=1;j=2*i-1;j++)//打印*

{

System.out.print("*");

}

System.out.println();

}

for(int i=n-1;i=1;i--)

{

for(int k=i;k=n-1;k++)

{

System.out.print(" ");

}

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

{

System.out.print("*");

}

System.out.println();

}

}

请问怎么用 java 画菱形~~~~~~?????????

java 输出菱形代码:

package demo;

public class Demo01 {

public static void main(String[] args) {

int i, j, k;

for (i = 1; i = 5; i++) {

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

System.out.print(" ");

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

System.out.print("*");

System.out.println("");

}

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

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

System.out.print(" ");

for (k = 1; k = 9 - 2 * i; k++)

System.out.print("*");

System.out.println("");

}

}

}

绘制算法:

1、分为两部分,上半部分和下半部分

2、输出空格部分换个输出*部分

3、最后一个标签需要换行

用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();


文章名称:用java代码写一个菱形 用java代码写一个菱形图案
转载来于:http://6mz.cn/article/dojepgp.html

其他资讯