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();
}
}
}
}
展开