黑马程序员技术交流社区
标题: 给大家分享几个比较常用的经典图形,希望初学者动手做做. [打印本页]
作者: NO? 时间: 2014-3-29 23:07
标题: 给大家分享几个比较常用的经典图形,希望初学者动手做做.
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();
}
}
作者: 许庭洲 时间: 2014-4-1 14:09
值得学习ing!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |