for循环打印的练习
来源:互联网 发布:centos 6.5安装教程 编辑:程序博客网 时间:2024/05/31 05:28
1.数字的练习
for(int a=1;a<=5;a++){ for(int b=1;b<=a;b++){ System.out.print(b); } System.out.println(); } /* 1 12 123 1234 12345 */ System.out.println("--------------------------"); for(int a=1;a<=5;a++){ for(int b=1;b<=a;b++){ System.out.print(a); } System.out.println(); } /* 1 22 333 4444 55555*/ System.out.println("--------------------------"); for(int a=5;a>0;a--){ for(int b=a;b>0;b--){ System.out.print(b); } System.out.println(); } /* 54321 4321 321 21 1*/ System.out.println("--------------------------"); for(int a=5;a>0;a--){ for(int b=1;b<=a;b++){ System.out.print(b); } System.out.println(); } /* 12345 1234 123 12 1 */ System.out.println("--------------------------"); for(int a=1;a<=5;a++){ for(int b=5;b>=a;b--){ System.out.print(b); } System.out.println(); } /* 54321 5432 543 54 5 */
2.打印直角三角形
for(int a=1;a<=5;a++){ for(int b=1;b<=a;b++){ System.out.print("*"); } System.out.println(); } /* * ** *** **** ***** */ System.out.println("----------------------"); for(int a=1;a<=5;a++){ for(int b=5;b>=a;b-- ){ System.out.print("*"); } System.out.println(); } /* ***** **** *** ** * */ System.out.println("----------------------");
**3.等腰三角形**
for(int a=1;a<=5;a++){ for(int b=5;b>=a;b--){ System.out.print(" "); } for(int z=1;z<=a;z++){ System.out.print(" *"); } System.out.println(); } /* * * * * * * * * * * * * * * * */ System.out.println("----------------------"); for(int a=1;a<=5;a++){ for(int b=1;b<=a;b++){ System.out.print(" "); } for(int z=5;z>=a;z--){ System.out.print(" *"); } System.out.println(); } /* * * * * * * * * * * * * * * * */ System.out.println("----------------------");
4.输出菱形
for(int a=1;a<=5;a++){ for(int b=5;b>=a;b--){ System.out.print(" "); } for(int z=1;z<=a;z++){ System.out.print("* "); } System.out.println(); } for(int a=1;a<=5;a++){ for(int b=1;b<a+1;b++){ //消除重复的那一行 System.out.print(" "); } for(int z=4;z>=a;z--){ //去掉个最长的五个 System.out.print(" *"); } System.out.println(); } /* * * * * * * * * * * * * * * * * * * * * * * * * * */ System.out.println("----------------------");
5.四边形
for(int a=1;a<=5;a++){ for(int b=1;b<=5;b++){ System.out.print("*"); } System.out.println(); } /* ***** ***** ***** ***** ***** */
最后,思想很重要,一步一步脚踏实地的,不要把自己绕晕了,从直角到等腰再到菱形,加油。
阅读全文
0 0
- for循环打印的练习
- js for循环的练习 99乘法表疯狂打印
- for循环的练习
- for循环练习——打印九九乘法表
- for 循环--之--打印星星练习
- 关于for循环的练习
- for循环练习,在控制台逆序打印一个输入的正整数
- 分享一些简单的for循环练习
- for循环打印字典
- for循环打印金字塔
- for循环打印菱形
- for循环打印矩形
- 【for循环】打印九九乘法表
- 【for循环】打印菱形
- for循环 打印等腰三角形
- for循环打印金字塔
- if--else的练习,for练习,算法,金字塔,菱形打印
- for循环练习【20171113练习】
- 排序算法--冒泡排序法
- OpenGL中各个坐标系的转化
- 相关linux脚本小技巧
- day08-js语法和常用类
- Java synchronized 中的 while 和 notifyAll
- for循环打印的练习
- 常用的数组的方法(写给自己)
- 关于WebAssembly的一些介绍和开发
- 第二周项目二C/C++程序的多文件组织
- Mysql-5.7 基于GTID主从复制
- 编辑从字节码和 JVM 的角度解析 Java 核心类 String 的不可变特性
- C++设计模式——单例模式(总结比较全面)
- 算法题--两种排序方法
- JVM内存回收策略