没有合适的资源?快使用搜索试试~ 我知道了~
旋转矩阵元素的Java程序.docx
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 60 浏览量
2023-07-27
07:32:29
上传
评论
收藏 28KB DOCX 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/88105513/0001-61d9dcc8bdcbc0b3c199f8ce1283da3d_thumbnail-wide.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
12页
每个 Java 程序都会为您提供不同的方法来解决 Java 中的特定问题。如果您是 Java 编程新手,我们强烈建议您阅读有关Java 教程的文章,其中我们通过实际示例和程序介绍了 Java 编程的所有基础知识和高级主题。
资源推荐
资源详情
资源评论
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/88105513/bg1.jpg)
旋转矩阵元素的 Java 程序
矩阵只是一个二维数组。因此,目标是处理元素所在的固定索引,并对索引
执行操作,以便在矩阵旋转时应以这种方式交换寻址上的元素。这里我们将
讨论处理索引的两种方法
1. 使用朴素的方法
2. 使用最佳方法
方法 1:使用朴素方法
对于给定的矩阵,任务是顺时针方向旋转其元素。
插图:
对于 4*4 矩阵输入:
7 8 9
10 11 12
2 3 4 输出:
10 7 8
2 11 9
3 4 12
对于 4*4 矩阵输入:
4 5 6 7
![](https://csdnimg.cn/release/download_crawler_static/88105513/bg2.jpg)
8 9 10 11
12 13 14 15
16 17 18 19 输出:
8 4 5 6
12 13 9 7
16 14 10 11
17 18 19 15
方法:
在这里,我们将使用循环来以螺旋形式打印元素。其中,我们将从最外层开
始,将元素的所有环一一旋转。为了旋转环,我们需要执行以下操作:
1. 移动顶行的元素,
2. 移动最后一列的元素,
3. 移动底行的元素,然后
4. 移动第一列的元素。
另外,如果还有内圈,则重复上述步骤。
例子:
� 爪哇
// Java Program to Rotate Matrix Elements
![](https://csdnimg.cn/release/download_crawler_static/88105513/bg3.jpg)
// Importing classes from java.lang package
import java.lang.*;
// Importing classes from java.util package
import java.util.*;
// main Class
class GFG {
static int r = 4;
static int c = 4;
// Method
// To rotate a matrix of
// dimension r x c. And initially,
// p = r and q = c
static void rotate_matrix(int p, int q, int matrix[][])
{
int rw = 0, cl = 0;
int previous, current;
// rw is the Starting row index
剩余11页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/32c5b83b0bcc48e0b964a47995717742_qq_52010446.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
Qshen
- 粉丝: 1638
- 资源: 418
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)