蛇形输出
来源:互联网 发布:淘宝乐高日本代购 编辑:程序博客网 时间:2024/06/06 06:48
private void snakeMatrix(int w, int h){ int x,y;//维度 int[][] numberMatric = new int[w][h]; int num = numberMatric[x = 0][y = 0] = 1; while(num < w*h){ //往右移动 while(y+1<h && numberMatric[x][y+1] == 0/*未填充默认的项其值为0*/){ y++; numberMatric[x][y] = ++num; } //往下移动 while(x+1<w && numberMatric[x+1][y] == 0){ x++; numberMatric[x][y] = ++num; } //往左移动 while(y-1>=0 && numberMatric[x][y-1] == 0){ y--; numberMatric[x][y] = ++num; } //往上移动 while(x-1>=0 && numberMatric[x-1][y] == 0){ x--; numberMatric[x][y] = ++num; } } //打印输出 for(x = 0;x < w;x++){ for(y = 0;y < h;y++){ System.out.printf("%4d",numberMatric[x][y]); } System.out.println();//换行 } }
0 0
- 蛇形输出
- 蛇形输出、螺旋输出
- 蛇形输出数组问题
- //输出蛇形数组
- //输出蛇形数组
- 打印输出蛇形矩阵
- 蛇形矩阵的输出
- 输出蛇形数组
- Java 输出蛇形矩阵
- 蛇形输出数组
- 蛇形输出一段数字
- 输出蛇形代码
- 输出蛇形代码
- 编程实现蛇形输出
- 实现蛇形输出
- 程序:输出蛇形代码
- 输出蛇形矩阵(java版)
- 不用数组输出蛇形矩阵
- W2.3 Hadoop2.6安装
- ES6.0 类定义之私有变量与私有函数
- Android Gradle上传Maven仓库
- CSDN日报20170514 ——《聪明的老板才不招工资低的程序员》
- 用gradle构建java项目
- 蛇形输出
- 水题hdu Identity Card
- ReactNative调研报告
- mybaits中批量插入操作注意点
- 正则化方法:L1和L2 regularization、数据集扩增、dropout
- centos7 mysql数据库安装和配置
- 06-图1 列出连通集 (25分)
- 读书笔记《Effective C++》条款20:宁以pass-by-reference-to-const替换pass-by-value
- HashCode和equal方法