/**
* Use nested loops to print rectangular triangular parallelogram diamonds separately
*/
public static void Main (string[] args) {
Printrect ();
Printsibianxing ();
Sanjiaxing ();
Lingxing ();
}
Print Rectangle
public static void Printrect () {
Outer loop output one line at a time *
for (int i = 1; I <= 5; i++) {
System.out.print ("*");
Inner loop output one at a time *
for (int j = 1; J <= 5; j +) {
System.out.print ("*");
}
System.out.println ();
}
}
Print a parallelogram
public static void Printsibianxing () {
Outer loop each time a *
for (int i = 1; I <=5; i++) {
Fill spaces
for (int j = 1; J <= 5-i; j) {
System.out.print ("");
}
Inner Loop prints one at a time *
for (int k = 1; k <= 5; k++) {
System.out.print ("*");
}
System.out.println ();
}
}
Print triangles
public static void Sanjiaxing () {
Outer loop control number of wheels (lines)
for (int i = 1; I <= 5; i++) {
for (int j = 0; J <= 5-i; j) {
System.out.print ("");
}
for (int k = 1; k <= 2 * i-1; k++) {
System.out.print ("*");
}
System.out.println ();
}
}
Print Diamond
public static void Lingxing () {
for (int i = 1; I <= 5; i++) {
for (int j = 0; J <= 5-i; j) {
System.out.print ("");
}
for (int k = 1; k <= 2 * i-1; k++) {
System.out.print ("*");
}
System.out.println ();
}
Print an inverted triangle
for (int m = 1; M <= 4; m++) {
Print spaces
for (int n = 0; n <= m; n++) {
System.out.print ("");
}
Print
for (int x = 1; <= 7-2 * (m-1); x + +) {
System.out.print ("*");
}
System.out.println ();
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.