java棱形图的代码 java中菱形代表什么
用java编写菱形
for(i=1;i=4;i++)
英吉沙网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站开发等网站项目制作,到程序开发,运营维护。创新互联于2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。
{
这个小的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 画菱形~~~~~~?????????
java 输出菱形代码:
package demo;
public class Demo01 {
public static void main(String[] args) {
int i, j, k;
for (i = 1; i = 5; i++) {
for (j = 1; j = 5 - i; j++)
System.out.print(" ");
for (k = 1; k = 2 * i - 1; k++)
System.out.print("*");
System.out.println("");
}
for (i = 1; i = 4; i++) {
for (j = 1; j = i; j++)
System.out.print(" ");
for (k = 1; k = 9 - 2 * i; k++)
System.out.print("*");
System.out.println("");
}
}
}
绘制算法:
1、分为两部分,上半部分和下半部分
2、输出空格部分换个输出*部分
3、最后一个标签需要换行
用java打印菱形。
一、整体实现思路:菱形9行9列可以将菱形分成上下两个三角形,分析每行空格数和星号个数的关系。
二、一个三角形的实现思路:以输出一个空心三角形为例:
(1)空格的输出按-1递减,字符的输出按等差数列,公差为2
(2)判断第一行和最后一行照常输出。
(3)中间行仅输出两个字符。
三、菱形分实心和空心两种,其代码及解析分别如下:
(一)实心菱形。
1、函数代码:
2、执行效果:
(二)空心菱形:
1、函数代码如下:
2、执行效果:
扩展资料:
java打印的输出方式解析:
1、print():print就是一般的标准输出,但是不换行。
2、println():println和print基本没什么差别,就是最后会换行。
要分辨清楚System.out.print()和System.out.println()的区别。System.out.print()是单纯的输出,而System.out.println()的功能是输出内容后换行,到达下一行,在使用时要注意区分两者之间的不同。
java 怎样写出一个菱形程序?空心和实心
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棱形图的代码 java中菱形代表什么
路径分享:http://myzitong.com/article/dogjpig.html