java 打印星号
2022/1/2 17:07:41
本文主要是介绍java 打印星号,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
代码1
package lesson.l2_for; //6列4行 //****** //****** //****** //****** public class ForDemo8 { public static void main(String[] args) { for (int i=1;i<=4;i++){ for (int j = 1; j <=6 ; j++) { System.out.print("*"); } System.out.println(); } } }
代码2
package lesson.l2_for; //打印 //* //** //*** //**** //***** public class ForDemo9 { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } } }
代码2-1
package lesson.l2_for; //打印 //**** //*** //** //* public class ForDemo10 { public static void main(String[] args) { for (int i = 4; i >= 1; i--) { for (int j = i; j >= 1; j--) { System.out.print("*"); } System.out.println(); } } }
代码2-2
package lesson.l2_for; //打印 //**** //*** //** //* public class ForDemo10_2 { public static void main(String[] args) { for (int i = 1; i <=4 ; i++) { for (int j = 1; j <=5-i ; j++) { System.out.print("*"); } System.out.println(); } } }
代码3
package lesson.l2_for; //打印 //* //** //*** //**** //***** //**** //*** //** //* public class ForDemo11 { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } for (int i = 1; i <= 4; i++) { for (int k = 1; k <= 5 - i; k++) { System.out.print("*"); } System.out.println(); } } }
代码4
package lesson.l2_for; //打印棱形 public class ForDemo12 { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <=6-i; j++) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(" *"); } System.out.println(); } for (int i = 1; i <=4 ; i++) { for (int j = 1; j <=i+1 ; j++) { System.out.print(" "); } //for (int j = i; j <=4; j++) { for (int j = 1; j <=5-i; j++) { System.out.print(" *"); } System.out.println(); } } }
代码5
package lesson.l2_for; //打印 // ********** // **** **** // *** *** // ** ** // * * // ** ** // *** *** // **** **** // ********** public class ForDemo13 { public static void main(String[] args) { //上半部分 for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 6 - i; j++) { System.out.print("*"); } for (int j = 1; j <= i - 1; j++) { System.out.print(" "); } for (int j = 1; j <= 6 - i; j++) { System.out.print("*"); } System.out.println(); } //下半部分 for (int i = 2; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } for (int j = 1; j <= 5 - i; j++) { System.out.print(" "); } for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } } }
这篇关于java 打印星号的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南