首页 > 其他 > 详细

【DAY2】输出正三角和倒三角的实验

时间:2016-05-13 05:08:07      阅读:156      评论:0      收藏:0      [点我收藏+]
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

【DAY2】输出正三角和倒三角的实验

原文:http://yehom.blog.51cto.com/5159116/1772605

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!