递归打印旋转正方形
2015-06-04 07:22
197 查看
package test; import java.util.Arrays; /** * * @author Administrator */ public class Square { final static char star='*'; final static char space=' '; static void nextRow(char[][] a,int row,int col){ a[row][col]=star; a[a.length-1-row][col]=star; if(col<a[0].length&&col>0&&row<a.length/2){ nextRow(a, row+1,col+1); nextRow(a, row+1,col-1); } } public static void main(String[] args) { int n=5; int peak=n-1; char[][] s=new char[2*n-1][2*n-1]; nextRow(s, 0,peak); String m; for(char[] a:s){ m=Arrays.toString(a).replace(',',space).replace('[', space).replace(']', space); System.out.println(m); } } }
相关文章推荐
- Skype for Business Server 2015-07-边缘服务器-1-安装-先决条件
- 数字自然读法
- OSChina 周四乱弹 —— 染上这病,你注定孤独终老
- 计算机系统原理之CPU中断技术
- bind server.c
- udacity android 学习笔记: lesson 4 part a
- mysql初识之数据文件及其他文件
- hdfs指令集
- PDO and MySQLi which is better
- socket通信
- 转:devise使用
- udacity android学习笔记: lesson 3
- PHP use MySQLi
- Construct Binary Tree from Inorder and Postorder Traversal
- 一步一步跟我学习lucene(18)---lucene索引时join和查询时join使用示例
- Skype for Business Server 2015-06-持久聊天服务器-3-配置
- udacity 之 android学习笔记:lesson 2
- Skype for Business Server 2015-06-持久聊天服务器-2-部署
- 微软发布的Win10开发者指南视频
- Skype for Business Server 2015-06-持久聊天服务器-1-设计拓朴