当前位置:网站首页>Print right angle triangle, isosceles triangle, diamond
Print right angle triangle, isosceles triangle, diamond
2022-07-23 11:57:00 【shuo277】
One 、 Print right angle triangle
System.out.println(" Print right angle triangle ");
for (int i = 1; i <=3; i++) {
for (int j = 1; j <=i ; j++) {
System.out.print("*");
}
System.out.println();
}Two 、 Enter the height of the right triangle from the console
Each row * The number of is 1、3、5、7…
System.out.println(" Please enter the number of rows of right angle triangle :");
int hang=sc.nextInt();
for (int i = 1; i <= hang; i++) {
for (int j = 1; j <= i *2- 1; j++) {
System.out.print("*");
}
System.out.println();
}3、 ... and 、 Print inverted right triangle , According to console input
System.out.println(" Please enter the number of rows of inverted right angle triangle :");
int hang=sc.nextInt();
for (int i = 0; i < hang; i++) {
for (int j =hang; j >i;j--) {
System.out.print("*");
}
System.out.println();
}Four 、 Print isosceles triangle , According to console input
System.out.println(" Please enter the number of rows of isosceles triangle :");
int number=sc.nextInt();
for (int i=1;i<=number;i++){
for (int j=number;j>=i;j--){
System.out.print(" ");
}
for (int k=1;k<=2*i-1;k++){
System.out.print("*");
}
System.out.println();
}5、 ... and 、 Print diamond , If the number of lines entered by the user is odd , Then print out the diamond ; Otherwise, the user will be prompted to enter an odd number
System.out.println(" Please enter the number of diamond rows :");
int rows=0;
rows = sc.nextInt();
while (rows%2==0){
System.out.println(" Please enter an odd number :");
rows=sc.nextInt();
}
int number=(rows+1)/2;
// Print the top half of the diamond
for(int i = 1; i <= number; i++){// Outer loop variables i Control the number of lines
for(int j = 1; j <= number-i; j++){// Inner loop variables j Control the number of spaces in this line
System.out.print(" ");
}
for(int k = 1; k <= 2*i-1; k++){// Inner loop variables k Control this line * Number
System.out.print("*");
}
System.out.print("\n");
}
// Print the lower half of the diamond
for(int i = number-1; i >= 1; i--) {
for (int j = 1; j <= number - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.print("\n");
}
边栏推荐
- 对.h5文件的迭代显示,h5py数据操作
- BST树
- 分治与递归(练习题)
- Digital collection development / digital collection system development solution
- MySQL index
- uni原生插件开发--友盟一键登录
- 使用飞桨的paddleX-yoloV3对钢材缺陷检测开发和部署
- Data warehouse 4.0 notes - user behavior data collection I
- MySQL storage engine
- Data warehouse 4.0 notes - user behavior data generation
猜你喜欢
随机推荐
NFT digital collection development: what are the possible application scenarios of digital collections in the future?
[hudi]hudi compilation and simple use of Hudi & spark and Hudi & Flink
MySQL事务
二叉树
10、I/O 输入输出流
链栈
方法的定义应用
MySQL卸载
MySQL user management
Kubesphere haproxy+kept (I)
MySQL invalid conn troubleshooting
飞桨高层API实现图像去雨
Data warehouse 4.0 notes - user behavior data generation
3.1. Simplified supplement to DQL
10. I/o input / output stream
Development of digital collection system: enterprise layout meta universe digital collection
UItextview的textViewDidChange的使用技巧
[uiautomation] key instructions (and three call methods) + common mouse actions +sendkeys+inspect learning
3. DQL (data query statement)
MySQL数据库









