我給你寫了一個,參考一下吧。。import java.util.*;
鐵力網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)建站從2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。
public class H
{
public static void main(String args[])
{
int a,b,c,N;
System.out.println("請輸入菱形的邊長N");
N=new Scanner(System.in).nextInt();
for(a=0;aN;a++)
{
for(b=0;b=N-a;b++)
System.out.print(" ");
for(c=1;c=2*a-1;c++)
{
if(c==1||c==2*a-1)
System.out.print("*");
else
System.out.print(" ");
}
System.out.print("\n");
}
for(a=0;a=N;a++)
{
for(b=0;b=a;b++)
System.out.print(" ");
for(c=1;c=2*(N-a)-1;c++)
if(c==1||c==2*(N-a)-1)
System.out.print("*");
else
System.out.print(" ");
System.out.print("\n");
}
}
}
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();
import java.util.Scanner;
public class Diamond {
public static void main(String[] args) {
int length=1;//存儲菱形的邊長的變量
Scanner sc =new Scanner(System.in);//輸入數(shù)據(jù)的掃描對象
System.out.println("請輸入菱形的邊長:");
length = sc.nextInt();//獲取輸入的邊長數(shù)值
/*打印菱形的上半部分三角形 行數(shù)為length行*/
for (int i=1; i=length;i++) {//需要打印的行數(shù)
for(int j=1;j=length-i;j++){//打印左邊空白的區(qū)域,隨行遞減1
System.out.print(" ");
}
for(int k=1;k=2*i-1;k++){//打三角形的區(qū)域
if(k==1||k==2*i-1){//空心的獲取 除每行第一個以及最后一個 外其余為空白
System.out.print("*");
}else{
System.out.print(" ");
}
}
System.out.println();
}
/*打印菱形的下半部分三角形 中間行公用 故行數(shù)為length-1*/
for (int i = length-1;i0;i--){
for(int j=1;j=length-i;j++){
System.out.print(" ");
}
for(int k=1;k=2*i-1;k++){
if(k==1||k==2*i-1){
System.out.print("*");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
Console.Write("請輸入要打印的行數(shù)(奇數(shù)):");
int n = int.Parse(Console.ReadLine()) / 2 + 1; //這樣就算出上部分的總行數(shù)了
for (int i = 1; i = n; i++)
{
for (int j = 1; j = n - i; j++)
{
Console.Write(" ");
}
for (int k = 1; k = 2 * i - 1; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
for (int i = 1; i n; i++)
{
for (int j = 1; j = i; j++)
{
Console.Write(" ");
}
for (int k = 1; k = (2 * n - 1) - 2 * i; k++)
{
Console.Write("*");
}
Console.WriteLine();
}