java转置矩阵的代码 java转置矩阵的代码有哪些

Java 3*5矩阵?可以如下操作java转置矩阵的代码:
int[][] num = new int [5][3];
//num为5*3java转置矩阵的代码的二位数组
init(num);
//为num数组负值
for(int i=0;i3;i++)
{
for(int j=0;j5;j++)
{
System.out.print(num[j][i]);
System.out.print(" ");
}
System.out.print("\n");
}
//双重for循环实现二维数组java转置矩阵的代码的转置输出
That's all.
一维数组Java转置方法怎么写?。?/h2>一维数组java转置可以使用数组下标修改来实现java转置矩阵的代码,示例如下java转置矩阵的代码:
int[] array = {1,2,3,4,5,6};//一维int数组
for(int i = 0;iarray.length/2;i++){
int temp = array[i];//中间变量
array[i] = array[array.length-i-1];//进行转置
array[array.length-i-1]=temp;//转置完成
}
【JAVA】请教,在线等,急急急!这是我写的一个工厂类  , 你先看吧,不明白的地方再问
翻转我用的是矩阵转置的算法
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class Brick {
int x;
int y;
int style;
int color;
int movable=1;
int BLOCK_W ;
int BLOCK_H ;
//方块类型
//中心对称
private final static int S = 0;
private final int Z = 1;
private final int I = 4;
//完全翻转
private final int L = 2;
private final int J = 3;
private final int T = 6;
//无需翻转
private final int O = 5;
byte [][] matrix;
byte[][] tempMatrix = new byte[4][4];
Matrix mat;
/**方块图片*/
Image imgBigBrick[];
Image imgMiniBrick[];
// tetrisCanvas can = new tetrisCanvas(null);
//键值
//KEY_CODE
final static int KEY_LEFT = 4;
final static int KEY_RIGHT = 32;
final static int KEY_UP = 2;
final static int KEY_DOWN = 64;
public Brick(){
mat = new Matrix();
try {
imgBigBrick = new Image[8];
imgMiniBrick = new Image[8];
for(int j=0;j8;j++){
//imgBrick[j] = new Image();
imgBigBrick[j] = Image.createImage("/gameres/0"+(j+1)+".png");
imgMiniBrick[j] = Image.createImage("/gameres/00"+(j+1)+".png");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setMatrix(){
switch(this.style){
case S:
this.getMatrix(this.matrix, mat.matrixs,4);
break;
case Z:
this.getMatrix(this.matrix, mat.matrixz,4);
break;
case I:
this.getMatrix(this.matrix, mat.matrixi,4);
break;
case L:
this.getMatrix(this.matrix, mat.matrixl,4);
break;
case J:
this.getMatrix(this.matrix, mat.matrixj,4);
break;
case T:
this.getMatrix(this.matrix, mat.matrixt,4);
break;
case O:
this.getMatrix(this.matrix, mat.matrixo,4);
break;
}
}
//旋转
public void turn(byte[][] scene){
//记录之前的矩阵后转动,若不可转再还原
if(this.style!=O){//如果是O就不翻转
if(this.style == Ithis.x == 162){
}else{
this.getMatrix(tempMatrix,this.matrix,4);
this.doTurn(tempMatrix);
}
if(this.checkCollision(scene,tempMatrix,this.x,this.y,0,0)!=1)
this.getMatrix(this.matrix, tempMatrix,4);
}
}
//快速下落到底
public void down(byte[][] scene){
while(this.checkCollision(scene,this.matrix,this.x,this.y+BLOCK_H,0,0)!=1){
this.y +=BLOCK_H;
}
}
//正常下落
public void drop(byte[][] scene){
if(this.checkCollision(scene,this.matrix,this.x,this.y+BLOCK_H,0,0)!=1)
this.y += BLOCK_H;
else this.movable = 0;
}
//平移

推荐阅读