java不空心菱形代码 java实心菱形代码

Java打印菱形高效简洁代码

public class shu{

10多年的扎囊网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整扎囊建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“扎囊网站设计”,“扎囊网站推广”以来,每个客户项目都认真落实执行。

public static void main(String[] a){

for(int i=0;i6;i++){

for(int j=6-i;j0;j--){

System.out.print(" ");

}

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

System.out.print("*");

}

System.out.println();

/*以上是打印了一个上等腰三角形*/

for(int i=6;i=0;i--){

for(int j=6-i;j0;j--){

System.out.print(" ");

}

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

System.out.print("*");

}

System.out.println();

}

}

}

只要把for的数据换下  下等腰三角形就出来了,所以原理其实就是打印2个等腰三角形

用java编写菱形

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

如何用Java通过#号打出囧字、菱形和空心菱形?

显示效果是这样的:

代码如下:

int hangshu = 11;

int yiban = hangshu / 2 + 1;

int yibanduo = hangshu / 2;

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

for(int k = 1;k = yiban;k++){

for(int i = 1;i = (yiban - 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 = yibanduo;k =1;k--){

for(int i = 1;i = (yiban - 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();

}

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

for(int i = 1;i = hangshu;i++){

if(i = hangshu/2 + 1){

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

System.out.print(" ");

}

for(int k = 1;k = i;k++){

System.out.print("* ");

}

System.out.println();

}else{

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

System.out.print(" ");

}

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

System.out.print("* ");

}

System.out.println();

}    

}

囧字再看看

高手指点一下,JAVA代码怎么打不出菱形出来去,新手请教

已修改,复制粘贴即可

public class Diamond

{

public static void main ( String[] args )

{

printHollowRhombus (10);

}

public static void printHollowRhombus ( int size )

{

if (size % 2 == 0)

{

size++;// 计算菱形大小

}

for ( int i = 0; i  size / 2 + 1; i++ )

{

for ( int j = size / 2 + 1; j  i + 1; j-- )

{

System.out.print (" ");// 输出左上角位置的空白

}

for ( int j = 0; j  2 * i + 1; j++ )

{

if (j == 0 || j == 2 * i)

{

System.out.print ("*");// 输出菱形上半部边缘

}

else

{

System.out.print (" ");// 输出菱形上半部空心

}

}

System.out.println ();

}

for ( int i = size / 2 + 1; i  size; i++ )

{

for ( int j = 0; j  i - size / 2; j++ )

{

System.out.print (" ");// 输出菱形左下角空白

}

for ( int j = 0; j  2 * size - 1 - 2 * i; j++ )

{

if (j == 0 || j == 2 * ( size - i - 1 ))

{

System.out.print ("*");// 输出菱形下半部边缘

}

else

{

System.out.print (" ");

}

}

System.out.println ();

}

}

}


分享题目:java不空心菱形代码 java实心菱形代码
转载来于:http://myzitong.com/article/dosjgic.html