当前位置:网站首页>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");
}
边栏推荐
- MySQL用户管理
- MySQL backup
- One of scala variables and data types
- Development of digital collection system / introduction of digital collection scheme
- Customized development of ant chain NFT digital collection DAPP mall system
- LearnOpenGL - Introduction
- Software test 1
- 10、I/O 输入输出流
- [untitled]
- Data warehouse 4.0 notes - Data Warehouse Modeling
猜你喜欢

NFT digital collection development: Jingdong "Qida bear takes you to the capital" tourism package

ninja启动过程

Digital collection development / digital collection system development solution

Websocket long connection

Machine learning algorithm for large factory interview (5) recommendation system algorithm

ChaosLibrary·UE4开坑笔记

New BPMN file used by activiti workflow

Develop necessary idea use

Data warehouse 4.0 notes - user behavior data collection III

10. I/o input / output stream
随机推荐
MySQL卸载
Service服务
查看真机APP里面沙盒文件
APP自动化测试工具-appium的安装及使用
Software test 1
Mysql database
MySQL transaction
Data warehouse 4.0 notes - business data collection
MySQL invalid conn troubleshooting
软件测试1
两个栈共用空间
ninja启动过程
Cuda10.0 configuration pytorch1.7.0+monai0.9.0
Modify the root password of MySQL
MySQL user management
Yarn capacity scheduler settings
抽象类和接口有什么区别?
What is the IP address
[hudi]hudi compilation and simple use of Hudi & spark and Hudi & Flink
九、实用类