5. 将一个5×5的二维数组转置到另一个5×5的二维数组(即沿主对角线翻转)(java语言).
1个回答
展开全部
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 ();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询