Java编程算法基础-自底向上风格

自顶向下:类比于 计划经济,需求变化时候显的很尴尬,需要变动很多东西

自底向上:自适应变化

 

在开发过程中,混合使用多种设计风格

 

 

 

 

 

 

 

 

 

 

 

 

package NO3;

import java.util.Scanner;
class cell{
	private int x;
	private int y;
	private int width;
	private int height;
	public cell(int x, int y, int width, int height){
	  	this.x = x;
	  	this.y = y;
	  	this.width = width;
	  	this.height = height;
	}
	public void draw(char[][] a){
		/*for(int i = x; i < x + width ;i++){
		     a[y][i] = '$';
		}
	    for(int i = x; i < x + width ;i++)
		     a[y + height-1][i] = '$';
	   for(int i = y + 1;i < y + height; i++)
	         a[i][x]  = '$';
	   for(int i = 0; i < y + height;i++)
	        a[i][x + width-1 ] = '$';
	        */
		for(int i = 0; i < width; i++){
			  a[y][x + i] = '$';
			  a[y + height-1][x + i ] = '$';
		}
		
		for(int i = 0; i < height;i++){
			a[y+i][x] = '$';
		    a[y+i][x + width -1] = '$';    
		}
	}
	
	
}
public class Test04 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
      
		char[][] cache = new char[20][50];
		
		Scanner input = new Scanner(System.in);
		int line = input.nextInt();
		int row  = input.nextInt();
		//int width = input.nextInt();
		//int height = input.nextInt();
		for(int i = 0; i < line ;i++)
		   for(int j = 0; j <  row;j++){

        		  cell c1 = new cell(j*(5- 1) , i*(4 - 1), 5, 4);
		          c1.draw(cache);
		
	     	}
		
		
		print(cache);
	}

	private static void print(char[][] cache) {
		// TODO Auto-generated method stub
		for(int i = 0; i < cache.length; i++){
			for(int j = 0; j < cache[i].length; j++){
				
				if(cache[i][j] == 0)
					System.out.print(" ");
				else 
					System.out.print(cache[i][j]);
			}
		
		  System.out.println();
		}
	}

}
结果:
3
4
$$$$$$$$$$$$$$$$$                                 
$   $   $   $   $                                 
$   $   $   $   $                                 
$$$$$$$$$$$$$$$$$                                 
$   $   $   $   $                                 
$   $   $   $   $                                 
$$$$$$$$$$$$$$$$$                                 
$   $   $   $   $                                 
$   $   $   $   $                                 
$$$$$$$$$$$$$$$$$     


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值