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()
java 输出菱形代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package demo
public class Demo01 {
public static void main(String[] args) {
int i, j, k
for (i = 1i <= 5i++) {
for (j = 1j <= 5 - ij++)
System.out.print(" ")
for (k = 1k <= 2 * i - 1k++)
System.out.print("*")
System.out.println("")
}
for (i = 1i <= 4i++) {
for (j = 1j <= ij++)
System.out.print(" ")
for (k = 1k <= 9 - 2 * ik++)
System.out.print("*")
System.out.println("")
}
}
}
绘制算法:
1、分为雹前两部分,上半肢肆晌部分和下半部分
2、输出空格部分换个输出*部分
3、最后一个标签需要历锋换行
按照你的要求脊卜用Java语言编写的7行7列的菱形图的程序如下(Math.abs()是求绝对值的函数)
public class F6 {public static void main(String[] args) {
int N=4
for(int i=1i<=2*N-1i++){
for(int j=1j<=Math.abs(N-i)j++){
System.out.print(" ")
}
for(int j=1j<=2*N-1-Math.abs(i-N)*2j++){
颤野耐 茄春 System.out.print("*")
}
System.out.println()
}
}
}
运行结果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)