5. 将一个5×5的二维数组转置到另一个5×5的二维数组(即沿主对角线翻转)(java语言).
答案:1 悬赏:0 手机版
解决时间 2021-11-21 18:26
- 提问者网友:孤凫
- 2021-11-21 09:23
5. 将一个5×5的二维数组转置到另一个5×5的二维数组(即沿主对角线翻转)(java语言).
最佳答案
- 五星知识达人网友:逃夭
- 2021-11-21 10:06
package table;
public class Rect
{
public static void main ( String[] args )
{
int[][] orial = {{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15},
{16,17,18,19,20},
{21,22,23,24,25}};
for ( int[] is : orial )
{
for ( int i : is )
{
System.out.print (i + " ");
}
System.out.println ();
}
System.out.println ();
int[][] dest1 = new int[5][5];
for ( int i = 0; i < orial.length; i++ )
{
for ( int j = 0; j < orial[i].length; j++ )
{
dest1[i][j] = orial[orial.length - 1 - j][orial.length - 1 - i];
}
}
for ( int[] is : dest1 )
{
for ( int i : is )
{
System.out.print (i + " ");
}
System.out.println ();
}
System.out.println ("----------------------");
int[][] dest2 = new int[5][5];
for ( int i = 0; i < orial.length; i++ )
{
for ( int j = 0; j < orial[i].length; j++ )
{
dest2[i][j] = orial[j][i];
}
}
for ( int[] is : dest2 )
{
for ( int i : is )
{
System.out.print (i + " ");
}
System.out.println ();
}
}
}
public class Rect
{
public static void main ( String[] args )
{
int[][] orial = {{1,2,3,4,5},
{6,7,8,9,10},
{11,12,13,14,15},
{16,17,18,19,20},
{21,22,23,24,25}};
for ( int[] is : orial )
{
for ( int i : is )
{
System.out.print (i + " ");
}
System.out.println ();
}
System.out.println ();
int[][] dest1 = new int[5][5];
for ( int i = 0; i < orial.length; i++ )
{
for ( int j = 0; j < orial[i].length; j++ )
{
dest1[i][j] = orial[orial.length - 1 - j][orial.length - 1 - i];
}
}
for ( int[] is : dest1 )
{
for ( int i : is )
{
System.out.print (i + " ");
}
System.out.println ();
}
System.out.println ("----------------------");
int[][] dest2 = new int[5][5];
for ( int i = 0; i < orial.length; i++ )
{
for ( int j = 0; j < orial[i].length; j++ )
{
dest2[i][j] = orial[j][i];
}
}
for ( int[] is : dest2 )
{
for ( int i : is )
{
System.out.print (i + " ");
}
System.out.println ();
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯