java 怎样写出一个菱形程序?空心和实心

java 怎样写出一个菱形程序?空心和实心,第1张

java打印菱形通过二维数组来打印,实例如下:

int hangshu = 11

int yiban = hangshu / 2 + 1

int yibanduo = hangshu / 2

System.out.println("空心菱形:")

for(int k = 1k <= yibank++){

for(int i = 1i <= (yiban - k)i++){

System.out.print(" ")

}

System.out.print("*")

for(int i = 1i <= ( (k - 2) * 2 + 1)i++){

System.out.print(" ")

}

if(k != 1){

System.out.print("*")

}

System.out.println()

}

for(int k = yibanduok >=1k--){

for(int i = 1i <= (yiban - k)i++){

System.out.print(" ")

}

System.out.print("*")

for(int i = 1i <= ( (k - 2) * 2 + 1)i++){

System.out.print(" ")

}

if(k != 1){

System.out.print("*")

}

System.out.println()

}

System.out.println("实心菱形:")

for(int i = 1i <= hangshui++){

if(i <= hangshu/2 + 1){

for(int 段圆搭k = 腔配1k <= hangshu/2 + 1- ik++){

System.out.print(" ")

}

for(int k = 1k <= ik++){

System.out.print("* ")

}

System.out.println()

}else{

for(int k =1k <= (i -(hangshu/2 握拿+ 1))k++){

System.out.print(" ")

}

for(int k = 1k <= (2 *(hangshu/2 + 1) - i)k++){

System.out.print("* ")

}

System.out.println()

}

}

结果如下:

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

{

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

for(j=1j<=4-ij++)

System.out.print(" ")

这个是打印星星的

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

System.out.print("*"碧数)

这个是打印完一行的换行

System.out.println("")

}

下边的是一样的  只不过每一行的空格悔纤首和星星数   和上边竖则是翻过来的

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

{

for(j=1j<=ij++)

System.out.print(" ")

for(j=1j<=7-2*ij++)

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12491328.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存