大家帮忙给出经典的方法
今天没事儿做了个题,总感觉方法太笨,但还没想好别的写法,希望大家帮忙给出经典的方法。题目如下:
打印如下图形,
* * * * * * * * *
* * * *
* * * *
* * * *
* * *
* * * *
* * * *
* * * *
* * * * * * * * *
我的方法如下:
public class Test {
public static void main(String[] args) {
Test.printGraphics();
}
public static void printGraphics() {
int total_row = 17;
int total_col = 9;
for(int col = 1; col <= total_col; col++) {
for(int row = total_row; row >= 1; row--) {
if(col != 1 && col != 9) {
if(row == total_row / 2 + 1 || row == total_row / 2 + col || row == col || row == 2 * col - 1) {
System.out.print("* ");
}else {
System.out.print(" ");
}
}else {
if(col == 1 && row <= total_row / 2 + 1) {
System.out.print("* ");
}else if(col == 1 && row > total_row / 2){
System.out.print(" ");
}
if(col == 9 && row > total_row / 2) {
System.out.print("* ");
}else if(col == 9 && row < total_row / 2){
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
打印如下图形,
* * * * * * * * *
* * * *
* * * *
* * * *
* * *
* * * *
* * * *
* * * *
* * * * * * * * *
我的方法如下:
public class Test {
public static void main(String[] args) {
Test.printGraphics();
}
public static void printGraphics() {
int total_row = 17;
int total_col = 9;
for(int col = 1; col <= total_col; col++) {
for(int row = total_row; row >= 1; row--) {
if(col != 1 && col != 9) {
if(row == total_row / 2 + 1 || row == total_row / 2 + col || row == col || row == 2 * col - 1) {
System.out.print("* ");
}else {
System.out.print(" ");
}
}else {
if(col == 1 && row <= total_row / 2 + 1) {
System.out.print("* ");
}else if(col == 1 && row > total_row / 2){
System.out.print(" ");
}
if(col == 9 && row > total_row / 2) {
System.out.print("* ");
}else if(col == 9 && row < total_row / 2){
System.out.print(" ");
}
}
}
System.out.println();
}
}
}
...全文
相关推荐
LTI规范的说明:H2和Hinf:给出了几种计算H2和Hinf规范的经典方法,并说明了(非)平滑性。-matlab开发
这里的重点是给出一些代码行,说明什么是 LTI 系统的 H2 和 Hinf 范数。 从这个意义
经典管理著作的学习方法
《经典管理著作的学习方法》 关键词: 管理学、经典著作、学习方法、案例分析、应用实践 摘要: 本文章旨在探讨经典管理著作的学习方法,通过详细解读泰勒《科学管理原理》、法约尔《工
经典阅读:夯实认知的必由之路
《经典阅读:夯实认知的必由之路》 关键词: 经典阅读、认知发展、阅读方法、实践技巧、书籍解读、社会影响 摘要: 本文深入探讨了经典阅读在个人认知发展和知识积累中的重要性,
经典力学中的数学方法.
伽利略构造涉及时间和空间的概念,在经典力学中占有特殊地位。伽利略构造描述了时间间隔和同时性事件的关系,给出了描述物体运动时必须遵守的规则。
经典数学物理方法书籍
### 经典数学物理方法书籍知识点详述#### 标题与描述解析- **标题**:“经典数学物理方法书籍”- **描述**:“物理学中需要用到的基础数学知识,很好的一本书”该书作为数学物理方法的经典之作,


Java SE
