新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

矩阵导入java代码 java实现矩阵

java中怎么把矩阵读入二维数组啊?

public class Test {

创新互联于2013年创立,是专业互联网技术服务公司,拥有项目成都网站制作、成都做网站、外贸营销网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元准格尔做网站,已为上家服务,为准格尔各地企业和个人服务,联系电话:13518219792

//转换为line*column数组

public void input(int[] datas,int line,int column){

int[][] arr = new int[line][column];

int l=0;

for(int i=0;iline;i++){

for(int j=0; jcolumn; j++){

arr[i][j] = datas[l];

l++;

}

}

//输出测试

for(int i=0;iline;i++){

for(int j=0; jcolumn; j++){

System.out.print(arr[i][j] + " ");

}

}

}

public static void main(String[] args){

int[] datas = {1,2,3,4,5,6,7,8,9};

Test t = new Test();

t.input(datas, 3, 3);

}

}

JAVA建立一个5行4列的矩阵(数值直接在程序代码中给定),

public class TestMatrix {

public static void main(String[] args){

int[][] a = {{2,4,1,4},{3,4,5,6},{0,1,2,3},{5,3,9,8},{1,2,3,4}};

int min = a[0][0];

int max = a[0][0];

int minrow = 0;

int mincol = 0;

int maxrow = 0;

int maxcol = 0;

for(int i = 0;i 5;i++){

for(int j = 0;j 4;j++){

if(a[i][j] = min){

min = a[i][j];

minrow = i;

mincol = j;

}

if(a[i][j] max){

max = a[i][j];

maxrow = i;

maxcol = j;

}

}

}

System.out.println("Min is:" + min + " Row is:" + minrow + " col is:" + mincol);

System.out.println("Max is:" + max + " Row is:" + maxrow + " col is:" + maxcol);

}

}

一、用JAVA编写程序实现矩阵乘积;int a[][]={{1,2,3},{4,5,6},{7,8,9}};求大神解答……谢谢

public class TestArrays{

public static void main(String []args){

int[][] a=new int[3][3];

int[][] b=new int[3][3];

int[][] c=new int[3][3];

//循环出两个二维数组,如果是给定的数组,就可以直接写最后的一个循环了

Ststem.out.println("矩阵A是:");

for(int i=0;ia.length;i++){

for(int j=0;ja[0].length;j++){

a[i][j]=(int)((Math.random())*10);

System.out.print(a[i][j]+" ");

}

}

Ststem.out.println("矩阵B是:");

for(int i=0;ib.length;i++){

for(int j=0;jb[0].length;j++){

b[i][j]=(int)((Math.random())*10);

System.out.print(b[i][j]+" ");

}

}

Ststem.out.println("矩阵A X B是:");

for(int i=0;ic.length;i++){

for(int j=0;jc[0].length;j++){

c[i][j]=0;

for(int k=0;kc.length;k++){

c[i][j]=a[i][k]*b[k][j]|d[i][j];

}

System.out.print(d[i][j]+" ");

}

System.out.println();

}

}

}

如何用java编写一个矩阵的转置?

(别说格式有问题代码就是这样的)编写矩阵显示方法,用于显示我们的矩阵数据;

private static void printArray(int[][] arr){

for(int i=0;iarr.length;i++){

for(int j=0;jarr.length;j++){

System.out.print(arr[i][j]+" ");

}

System.out.println();

填写一个要求解转置的矩阵方法;

编写行变列列变行的代码,即实现我们的矩阵值装置求解方法;

public static void main(String[] args) {

int arr[][] =new int[][]{{1,2,3},{4,5,6},{7,8,9}};

System.out.println("行列互换前");

printArray(arr);

int arr2[][]=new int[arr.length][arr.length];

for(int i=0;iarr.length;i++){

for(int j=0;jarr.length;j++){

arr2[i][j]=arr[j][i];

}

}

System.out.println("行列互换后:");

printArray(arr2);

用java声明Matrix类表示矩阵,使用二维数组存储矩阵元素,实现以下方法:

public class Matrix {

private static String matrix_A;

private int mx[][], m, n;

public Matrix(int r, int c) {

m = r;

n = c;

mx = new int[m][n];

iniMatrix();

}

public Matrix() {

m = 3;

n = 3;

mx = new int[3][3];

iniMatrix();

}

public void iniMatrix()// 随机取数

{

int i, j;

for (i = 0; i = m - 1; i++)

for (j = 0; j = n - 1; j++)

mx[i][j] = (int) (Math.random() * 100);

}

public void tranMatrix()// 转置矩阵

{

int i, j, t;

int mt[][] = new int[m][n];

for (i = 0; i = m - 1; i++)

for (j = 0; j = n - 1; j++)

mt[i][j] = mx[i][j];

t = m;

m = n;

n = t;

mx = new int[m][n];

for (i = 0; i = m - 1; i++)

for (j = 0; j = n - 1; j++)

mx[i][j] = mt[j][i];

}

public void printMatrix()// 输出矩阵所有值

{

int i, j;

for (i = 0; i = m - 1; i++) {

for (j = 0; j = n - 1; j++)

System.out.print(" " + mx[i][j]);

System.out.println();

}

}

//判断一个矩阵是否为上三角矩阵

public boolean isUpperTriangularMatrix() {

int i, j = 0;

int c = this.mx[1][0];

for(i=1; ithis.mx.length; i++)

for(j=0; ji; j++)

if(this.mx[i][j] != c)

break;

if(i=this.mx.length)

return true;

return false;

}

public void addMatrix(Matrix b)// 矩阵相加

{

int i, j;

for (i = 0; i = m - 1; i++)

for (j = 0; j = n - 1; j++)

mx[i][j] = mx[i][j] + b.mx[i][j];

}

public static void main(String args[]) {

Matrix ma = new Matrix(4, 3);

Matrix mb = new Matrix(4, 3);

System.out.println("The matrix_A:");

ma.printMatrix();

System.out.println("The matrix_B:");

mb.printMatrix();

if(ma.isUpperTriangularMatrix())

System.out.println("上三角矩阵:\n" + ma.isUpperTriangularMatrix());

System.out.println("Matrix_A + Matrix_B:");

ma.addMatrix(mb);

ma.printMatrix();

System.out.println("Transpose Matrix_A:");

mb.tranMatrix();

mb.printMatrix();

System.out.println("Transpose Matrix_A+Matrix_B:");

mb.tranMatrix();

mb.printMatrix();

}

}

java编写程序,提示用户输入一个方阵的长度,随机地在矩阵中填入0或1,打印这个矩阵,然后找出整行

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);

System.out.print("Enter the size for the matrix: ");

int size = input.nextInt();

int [][] array = new int [size][size];

for(int i = 0;isize;i++) {

for(int a = 0;asize;a++) {

array[i][a]=(int)(Math.random()*2);

System.out.print(array[i][a]+" ");

}

System.out.println();

}

row(array);

column(array);

diagonal(array);

subdiagonal(array);

}

public static void row(int [][] array) {

boolean bool = true ;

for(int i=0;iarray.length;i++) {

bool = true;

for(int a=0;aarray[i].length-1;a++) {

if(array[i][a]!=array[i][a+1]) {

bool = false;

}

}

if(bool) {

System.out.println((i+1)+" hang is "+array[i][0]);

}

}

}

public static void column(int [][] array) {

boolean bool = true ;

for(int a=0;aarray.length;a++) {

bool = true;

for(int i=0;iarray[a].length-1;i++) {

if(array[i][a]!=array[i+1][a]) {

bool = false;

}

}

if(bool) {

System.out.println((a+1)+" lie is "+array[0][a]);

}

}

}

public static void diagonal(int [][] array) {

boolean bool = true ;

int i;

for(i=0;iarray.length-1;i++) {

if(array[i][i]!=array[i+1][i+1]) {

bool = false;

}

}

if(bool) {

System.out.println("major diagonal is "+array[i][i]);

}

}

public static void subdiagonal(int [][] array) {

boolean bool = true ;

for(int i=array.length-1;i0;i--) {

for(int a = array.length-i-1;aarray.length-i;a++) {

if(array[i][a]!=array[i-1][a+1]) {

bool = false;

}

}

}

if(bool) {

System.out.println("sub-diagonal is "+array[0][array.length-1]);

}

}

}


分享标题:矩阵导入java代码 java实现矩阵
路径分享:http://wjwzjz.com/article/docehee.html
在线咨询
服务热线
服务热线:028-86922220
TOP