1. 想不想要以下图形 //矩形 ***** ***** ***** ***** ***** public class xingzhuang { public static void main(String[] args) { for (int x = 1;x <= 5 ;x++ ) { for (int y = 1;y <= 5 ;y++ ) { System.out.print("*"); } System.out.println(); } } 2.//三角形 * ** *** **** ***** public class xingzhuang { public static void main(String[] args) { for (int x = 1;x <= 5 ;x++ ) { for (int y = 1;y <= x ;y++ ) { System.out.print("*"); } System.out.println(); } } 3.//倒三角 ***** **** *** ** * public class xingzhuang { public static void main(String[] args) { for (int x = 1;x <= 5 ;x++ ) { for (int y = x;y <= 5 ;y++ ) { System.out.print("*"); } System.out.println(); } } 4.//等腰三角形 * * * * * * * * * * * * * * * public class xingzhuang { public static void main(String[] args) { for (int x = 1;x <= 5 ;x++ ) { for (int z = x;z <=4 ;z++ ) { System.out.print(" "); } for (int y = 1;y <= x ;y++ ) { System.out.print("* "); } System.out.println(); } } 5.//倒等腰三角形 * * * * * * * * * * public class xingzhuang { public static void main(String[] args) { for (int a = 1;a <= 4 ;a++ ) { for (int c = 1;c <= a ;c++ ) { System.out.print(" "); } for (int b = a;b <= 4 ;b++ ) { System.out.print("* "); } System.out.println(); } } 6.//空心矩形 ***** * * * * * * ***** public class xingzhuang { public static void main(String[] args) { for (int x = 1;x <= 5 ;x++ ) { for (int y = 1;y <= 5 ;y++ ) { if (x == 1 || x == 5 || y == 1 || y == 5) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } 7.//空心菱形 ◇ * * * * * * * * * * * * * * * * public class xingzhuang { public static void main(String[] args) { for (int x = 1;x <= 5 ;x++ ) { for (int z = x;z <=4 ;z++ ) { System.out.print(" "); } for (int y = 1;y <= x ;y++ ) { if(y == 1 || y == x){ System.out.print("* "); }else { System.out.print(" "); } } System.out.println(); } for (int a = 1;a <= 4 ;a++ ) { for (int c = 1;c <= a ;c++ ) { System.out.print(" "); } for (int b = a;b <= 4 ;b++ ) { if(b == a || b == 4) { System.out.print("* "); }else { System.out.print(" "); } } System.out.println(); } }
|