class Triangle2
{
public static void main(String[] args){
int x,y;
for(x=1;x<=5;x+=1){
for(y=1;y<=x+5;y+=1){
System.out.print("\t");
while(y==6-x){
System.out.print("*");
break;
}
}
//System.out.print("\t");
System.out.println("*");
while(x==5){
System.out.println("*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*");
break;
}
}
}
}编译显示:
倒三角:
class Triangle
{
public static void main(String[] args){
int x,y;
for(x=1;x<=5;x+=1){
while(x==1){
System.out.println("*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*"+"\t"+"*");
break;
}
for(y=1;y<=10-x;y+=1){
System.out.print("\t");
while(y==x){
System.out.print("*");
break;
}
}
while(x<5){
System.out.println("*");
break;
}
}
}
}编译显示:
本文出自 “yehomlab” 博客,请务必保留此出处http://yehom.blog.51cto.com/5159116/1772605
原文地址:http://yehom.blog.51cto.com/5159116/1772605