/**
成都創(chuàng)新互聯(lián)公司是專業(yè)的鎮(zhèn)巴網(wǎng)站建設(shè)公司,鎮(zhèn)巴接單;提供成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行鎮(zhèn)巴網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
*?輸出各種三角形,菱形,正方形
*?@author?young
*
*/
public?class?TrianglePrint?{
//?正三角
public?static?void?p1()?{
int?n?=?5;
int?a?=?0;
int?b?=?0;
for?(int?i?=?1;?i?=?n;?i++)?{
if?(a?!=?(n?-?i))?{
System.out.print("?");
a++;
i?=?i?-?1;
}?else?if?(b?!=?(2?*?i?-?1))?{
System.out.print("*");
b++;
i?=?i?-?1;
}?else?if?(a?==?(n?-?i)??b?==?(2?*?i?-?1))?{
System.out.println();
a?=?0;
b?=?0;
}
}
}
//?倒三角
public?static?void?p2()?{
int?n?=?5;
int?a?=?0;
int?b?=?0;
for?(int?i?=?n;?i?=?1;?i--)?{
if?(a?!=?(n?-?i))?{
System.out.print("?");
a++;
i?=?i?+?1;
}?else?if?(b?!=?(2?*?i?-?1))?{
System.out.print("*");
b++;
i?=?i?+?1;
}?else?if?(a?==?(n?-?i)??b?==?(2?*?i?-?1))?{
System.out.println();
a?=?0;
b?=?0;
}
}
}
//?倒三角:用戶決定行數(shù)
public?static?void?sta(int?n)?{
for?(int?i?=?0;?i??n;?i++)?{
for?(int?j?=?0;?j??i;?j++)?{
System.out.print("?");
}
for?(int?k?=?0;?k??2?*?(n?-?i)?-?1;?k++)?{
System.out.print("*");
}
System.out.println();
}
}
//?輸出正方形
public?static?void?zf(int?N)?{
for?(int?i?=?1;?i?=?N;?i++)?{
for?(int?j?=?1;?j?=?N;?j++)?{
if?(j?==?1?||?j?==?N?||?i?==?1?||?i?==?N)
System.out.print("*");
else
System.out.print("?");
}
System.out.println();
}
}
//?輸出正菱形
public?static?void?lx(int?n)?{
for?(int?i?=?0;?i??n?-?1;?i++)?{
for?(int?x?=?i?+?1;?x??n;?x++)?{
System.out.print("?");
}
for?(int?y?=?0;?y??(i?+?1)?*?2?-?1;?y++)?{
System.out.print("*");
}
System.out.println();
}
for?(int?i?=?0;?i??n;?i++)?{
for?(int?x?=?0;?x??i;?x++)?{
System.out.print("?");
}
for?(int?y?=?i;?y??2?*?n?-?i?-?1;?y++)?{
System.out.print("*");
}
System.out.println();
}
}
public?static?void?main(String[]?args)?{
p1();?//?正三角
System.out.println("------------");
p2();?//?倒三角
System.out.println("------------");
sta(5);?//?倒三角
System.out.println("------------");
zf(5);?//?正方形
System.out.println("------------");
lx(6);?//?菱形
}
}
總有一個是你要的
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("");
}
下邊的是一樣的 ?只不過每一行的空格和星星數(shù) ? 和上邊是翻過來的
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();
//連接數(shù)據(jù)庫
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打印菱形方法:
package?circulationDemo;
import?java.util.Scanner;
public?class?Test?{
public?static?void?main(String[]?args)?{
Scanner?input?=?new?Scanner(System.in);
System.out.println("請輸入要打印的行數(shù):");
int?num?=?input.nextInt();
t1(num);//?正直角
split();
t2(num);//?倒直角
split();
t3(num);//?等腰三角
split();
t4(num);//?等腰倒三角++
split();
t5(num);//?等腰倒三角--
split();
t6(num);//?實(shí)心菱形
split();
t7(num);//?空心菱形(1)
split();
t8(num);//?空心菱形(2)
split();
t9(num);//?空心菱形(3)
}
private?static?void?t9(int?num)?{
for?(int?k?=?1;?k?=?num;?k++)?{
for?(int?i?=?1;?i?=?(num?-?k);?i++)?{
System.out.print("?");
}
System.out.print("*");
for?(int?i?=?1;?i?=?((k?-?2)?*?2?+?1);?i++)?{
System.out.print("?");
}
if?(k?!=?1)?{
System.out.print("*");
}
System.out.println();
}
for?(int?k?=?num-1;?k?=?1;?k--)?{
for?(int?i?=?1;?i?=?(num?-?k);?i++)?{
System.out.print("?");
}
System.out.print("*");
for?(int?i?=?1;?i?=?((k?-?2)?*?2?+?1);?i++)?{
System.out.print("?");
}
if?(k?!=?1)?{
System.out.print("*");
}
System.out.println();
}
}
private?static?void?t8(int?num)?{
//?上半部分
for?(int?i?=?1;?i?=?num;?i++)?{
//?打印上半部分空格
for?(int?j?=?1;?j?=?num?-?i;?j++)?{
System.out.print("?");
}
//?打印原本實(shí)心的*部分
for?(int?j?=?1;?j?=?2?*?i?-?1;?j++)?{
//?僅在一行的開頭和末尾打印*
if?(j?==?1?||?j?==?2?*?i?-?1)?{
System.out.print("*");
}?else?{
System.out.print("?");
}
}
System.out.println();
}
//?下半部分
for?(int?i?=?1;?i?=?num?-?1;?i++)?{
for?(int?j?=?1;?j?=?i;?j++)?{
System.out.print("?");
}
for?(int?j?=?1;?j?=?2?*?(num?-?i?-?1)?+?1;?j++)?{
if?(j?==?1?||?j?==?2?*?(num?-?i?-?1)?+?1)?{
System.out.print("*");
}?else?{
System.out.print("?");
}
}
System.out.println();
}
}
private?static?void?t7(int?num)?{
//?打印上半部分
for?(int?i?=?1;?i?=?num;?i++)?{
//?打印空格
for?(int?j?=?1;?j?=?(num?-?i);?j++)?{
System.out.print("?");
}
//?打印*的個數(shù)
if?(i?==?1)?{
System.out.print("*");
}?else?{
System.out.print("*");
//?打印菱形里的空格
for?(int?j?=?1;?j?=?(2?*?i?-?3);?j++)?{
System.out.print("?");
}
System.out.print("*");
}
System.out.println();
}
//?打印下半部分
for?(int?i?=?num?-?1;?i??0;?i--)?{
//?打印空格
for?(int?j?=?1;?j?=?(num?-?i);?j++)?{
System.out.print("?");
}
//?打印*的個數(shù)
if?(i?==?1)?{
System.out.print("*");
}?else?{
System.out.print("*");
//?打印菱形里的空格
for?(int?j?=?1;?j?=?(2?*?i?-?3);?j++)?{
System.out.print("?");
}
System.out.print("*");
}
System.out.println();
}
}
private?static?void?t6(int?num)?{
//?上半部分
for?(int?i?=?1;?i?=?num;?i++)?{
for?(int?j?=?1;?j?=?num?-?i;?j++)?{
System.out.print("?");
}
for?(int?j?=?1;?j?=?2?*?i?-?1;?j++)?{
System.out.print("*");
}
System.out.println();
}
//?下半部分
for?(int?i?=?1;?i?=?num?-?1;?i++)?{
for?(int?j?=?1;?j?=?i;?j++)?{
System.out.print("?");
}
for?(int?j?=?1;?j?=?2?*?(num?-?1?-?i)?+?1;?j++)?{
System.out.print("*");
}
System.out.println();
}
}
private?static?void?t5(int?num)?{
for?(int?i?=?num;?i??0;?i--)?{
for?(int?j?=?1;?j?=?num?-?i;?j++)?{
System.out.print("?");
}
for?(int?j?=?1;?j?=?2?*?i?-?1;?j++)?{
System.out.print("*");
}
System.out.println();
}
回答于?2022-12-14