java55矩阵output_java矩阵问题 键盘输入两个矩阵然后输出,为什么输出不成了,求大神指点...

packagepri;importjava.util.Scanner;publicclassInterface{publicstaticvoidmain(String[]args){Scannerinput=newScanner(System.in);System.out.print("Enterthenumberoftransition...

package pri;

import java.util.Scanner;

public class Interface {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter the number of transition in matrix input: \n");

int transitionA = input.nextInt();

System.out.print("Enter the number of place in matrix input:\n");

int placeA = input.nextInt();

System.out.print("Enter the number of transition in matrix output: \n");

int transitionB = input.nextInt();

System.out.print("Enter the number of place in matrix putput:\n");

int placeB = input.nextInt();

if (transitionA != placeB) {

System.out.print("To multiply matrix input by matrix output, the number of "

+ "transition in a must be the same as the number" +

"of place in b.");

System.exit(0);

}

int[][] a = new int[transitionA][placeA];

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

for (int j1 = 0; j1 < a[0].length; j1++) {

System.out.print("Enter the element a[" + i1 + "][" + j1 + "]:\n");

a[i1][j1] = input.nextInt();

}

}

int[][] b = new int[transitionB][placeB];

for (int i2 = 0; i2 < b.length; i2++) {

for (int j2 = 0; j2 < b[0].length; j2++) {

System.out.print("Enter the element b[" + i2 + "][" + j2 + "]:\n");

b[i2][j2] = input.nextInt();}}

}

public static void print(int[][] a,int[][]b){

System.out.println("the input matrix you enter is:\n");

for(int i1=0;i1

for(int j1=0;j1

System.out.print(a[i1][j1]+" "

) ;

}

System.out.println("the output matrix you enter is:\n");

for(int i2=0;i2

for(int j2=0;j2

System.out.print(b[i2][j2]+" "

) ;

}

System.out.println();

}

}

}

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值