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();
參考下面主要代碼:
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();
}
}
public?class?PrintDiamond2{
public?static?void?main?(String?args[]){
int?TotalLayer=9;?
for(int?layer=1;?layer=TotalLayer;?layer++)?{
for(int?space=1;?space=Math.abs((TotalLayer+1)/2-layer);?space++){
System.out.print("?");
}
for(int?b=1;?b=TotalLayer-2*Math.abs((TotalLayer+1)/2-layer);?b++){
System.out.print("*");
}
System.out.println();
}
}
}
用3個for循環打出菱形,可以改變TotalLayer的值來改變菱形的大小
第一個for循環規定多少行
第二個for循環規定每行有多少個空格
第三個for循環規定每行有多少個星號
然后換行,重復2,3循環直到完成第一個循環
最后菱形完成
網頁題目:java代碼寫菱形 java編寫菱形以及空心菱形
文章位置:http://vcdvsql.cn/article4/hioooe.html
成都網站建設公司_創新互聯,為您提供ChatGPT、建站公司、動態網站、電子商務、網站營銷、定制網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯