星号*玩法升阶 输出菱形
来源:互联网 发布:inpho软件中文说明 编辑:程序博客网 时间:2024/05/16 09:04
/*需求;利用循环,使用“*”,输出一个三角形: 行数 空格数 星星*数 * 1 3 1 *** 2 2 3 ***** 3 1 5******* 4 0 7 i 4-i 2i-1*///分析:玩着玩着就发现,其实星号游戏是有规律的,正因为有规律我们才可以使用循环来实现它。// 1.发现数学逻辑// 2.java里面的循环来实现public class Test{public static void main(String[] args){for(int i=1;i<=4;i++){for(int j=1;j<=4-i;j++){System.out.print(" ");}for(int j=1;j<=2*i-1;j++){System.out.print("*");}System.out.println();}}}/*需求;利用循环,使用“*”,输出一个倒角形: 行数 空格数 星星*数******* 1 0 7 ***** 2 1 5 *** 3 2 3 * 4 3 1 i i-1 9-2i */public class Test{public static void main(String[] args){for(int i=1;i<=4;i++){for(int j=1;j<=i-1;j++){System.out.print(" ");}for(int j=1;j<=9-2*i;j++){System.out.print("*");}System.out.println();}}}/*需求;利用循环,使用“*”,输出一个实心的菱形: * *** ***** ******* ***** *** * *///分析:根据上面我们画出的正三角形和到三角形// 我们就想到了,把这个两个图形拼接到一起不就是一个菱形了么//但是要注意第四行~!//说就做!public class Test{public static void main(String[] args){for(int i=1;i<=4;i++){for(int j=1;j<=4-i;j++){System.out.print(" ");}for(int j=1;j<=2*i-1;j++){System.out.print("*");}System.out.println();}for(int j=1;j<=3;j++){for(int h=1;h<=j;h++){System.out.print(" ");}for(int h=1;h<=7-2*j;h++){System.out.print("*");}System.out.println();}}}
阅读全文
0 0
- 星号*玩法升阶 输出菱形
- 输出星号菱形
- 输出菱形星号
- 【C语言】输出菱形星号图案
- 习题 5.16 输出星号菱形图案
- 菱形星号
- 菱形星号
- 初阶一层的星号*玩法
- 在屏幕上输出星号组成的菱形图案。
- 根据用户需要输出打印菱形,用for循环输出打印星号组成的菱形
- 另一种菱形星号
- 打印菱形星号
- 打印菱形星号
- 打印菱形星号
- 用星号打印菱形
- 打印菱形星号
- 打印菱形星号组合
- 打印菱形星号组合
- 观察者模式
- 接口
- Android——对话框、通知
- Leetcode每日一练习
- centos系统下为python安装MySQLdb库
- 星号*玩法升阶 输出菱形
- Android中获取状态栏高度的有效方法
- 【luogu1080】国王游戏(高精度)
- 运算方法和运算器
- 【二叉树经典问题】105. Construct Binary Tree from Preorder and Inorder Traversal
- JSTL标签引入
- BZOJ 1863: [Zjoi2006]trouble 皇帝的烦恼 二分
- xml的解析方式(一)DOM 解析
- 微信公众号之(素材上传)群发消息