用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 怎样写出一个菱形程序?空心和实心java打印菱形通过二维数组来打?。?实例如下:
int hangshu = 11;
int yiban = hangshu / 21;
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) * 21);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) * 21);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/21){
for(int k = 1;k = hangshu/21- 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/21));k){
System.out.print(" ");
}
for(int k = 1;k = (2 *(hangshu/21) - i);k){
System.out.print("* ");
}
System.out.println();
}
}
结果如下:
用Java编写打印一段图形(类似菱形)的程序这个题目主要又两个难点:1.$符号不是一直增加,而是先增加,后减少 。2需要在$前补空格 。
代码如下:
public class PrintDollar {
public static void main(String[] args) {
// 总行数,可以修改
int row = 5;
// 每一行的$符号数量
int dollarNumber;
// 追加的空格数量
int spaceNumber;
String dollar = "$";
for (int i = 1; i = row; i) {
// 每一行输出的字符
String printString = "";
/*
* 判断行数是否超过了一半,超过一半$符号开始减少
*/
if (i * 2 - 1row) {
// 行数超过一半的情况
dollarNumber = (row - i) * 21;
spaceNumber = (row - dollarNumber) / 2;
} else {
// 行数没超过一半的情况
dollarNumber = i * 2 - 1;
spaceNumber = (row - dollarNumber) / 2;
}
//追加空格
for (int j = 0; jspaceNumber; j) {
printString= " ";
}
//追加$符号
for (int j = 0; jdollarNumber; j) {
printString= dollar;
}
System.out.println(printString);
}
}
}
如何用JAVA画一个菱形public class PrintDiamond2{
public static void main (String args[]){
int TotalLayer=9;
for(int layer=1; layer=TotalLayer; layer) {
for(int space=1; space=Math.abs((TotalLayer 1)/2-layer); space){
System.out.print(" ");
}
for(int b=1; b=TotalLayer-2*Math.abs((TotalLayer 1)/2-layer); b){
System.out.print("*");
}
System.out.println();
}
}
}
用3个for循环打出菱形,可以改变TotalLayer的值来改变菱形的大小
第一个for循环规定多少行
第二个for循环规定每行有多少个空格
第三个for循环规定每行有多少个星号
然后换行,重复2,3循环直到完成第一个循环
最后菱形完成
用Java编菱形图案1357531 * *** *****代码如下:
/**
*
*/
package main;
/**
* @author GT
*
*/
public class Mains {
/**
*
*/
public Mains() {
// TODO Auto-generated constructor stub
}
public static void print(int size) {
if (size % 2 == 0) {
size; // 计算菱形大小
}
for (int i = 0; isize / 21; i) {
for (int j = size / 21; ji1; j--) {
System.out.print(" "); // 输出左上角位置的空白
}
for (int j = 0; j2 * i1; j) {
System.out.print("*"); // 输出菱形上半部边缘
}
System.out.println(); // 换行
}
for (int i = size / 21; isize; i) {
for (int j = 0; ji - size / 2; j) {
System.out.print(" "); // 输出菱形左下角空白
}
for (int j = 0; j2 * size - 1 - 2 * i; j) {
System.out.print("*"); // 输出菱形下半部边缘
}
System.out.println(); // 换行
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
print(11);
}
}
【java图形菱形完整代码 菱形用java代码怎么搞】关于java图形菱形完整代码和菱形用java代码怎么搞的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 处理器在显卡上怎么看显存,处理器和显卡怎么看
- excel怎么居中字体,excell文字居中
- 抖音直播警告画面不清晰,抖音直播有点模糊怎么办?
- oracle怎么更新表 oracle查询表更新时间
- 公众号怎么重点标注,公众号怎么重点标注文章
- 开心视频小程序,开心视频搞笑视频动画
- 人像拍摄什么叶子,主要拍人像用什么镜头
- linux命令符号大全 linux 符号
- 七彩虹显卡1070怎么样,七彩虹1070显卡多少钱