重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java代码打印菱形星号 打印菱形javajava输出菱形

Java怎么用for循环打星号"*",打出一个空心菱形?

我给你写了一个,参考一下吧。。import java.util.*;

铁力网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联建站从2013年成立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站

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

}

}

}

用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中如何用星号如何输出个空心的菱形

import java.util.Scanner;

public class Diamond {

public static void main(String[] args) {

int length=1;//存储菱形的边长的变量

Scanner sc =new Scanner(System.in);//输入数据的扫描对象

System.out.println("请输入菱形的边长:");

length = sc.nextInt();//获取输入的边长数值

/*打印菱形的上半部分三角形 行数为length行*/

for (int i=1; i=length;i++) {//需要打印的行数

for(int j=1;j=length-i;j++){//打印左边空白的区域,随行递减1

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

}

/*打印菱形的下半部分三角形 中间行公用 故行数为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("请输入要打印的行数(奇数):");

int n = int.Parse(Console.ReadLine()) / 2 + 1; //这样就算出上部分的总行数了

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

}


当前文章:java代码打印菱形星号 打印菱形javajava输出菱形
网站链接:http://cqcxhl.com/article/dddcegh.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP