Java各种输入方法参考链接:
https://www.cpe.ku.ac.th/~jim/java-io.html
本文采用BufferedReader+StringTokenizer快速输入方法
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// Scanner in=new Scanner(System.in);
Reader.init( System.in ); // connect Reader to an input stream
// int m=in.nextInt();
// int s=in.nextInt();
// int n=in.nextInt();
int m=Reader.nextInt();
int s=Reader.nextInt();
int n=Reader.nextInt();
int[][] a=new int[m][s];
int[][] b=new int[s][n];
int[][] c=new int[m][n];
for(int i=0;i<m;i++) {
for(int j=0;j<s;j++) {
a[i][j]=Reader.nextInt();
}
}
for(int i=0;i<s;i++) {
for(int j=0;j<n;j++) {
b[i][j]=Reader.nextInt();
}
}
for(int i=0;i<m;i++) {
for(int k=0;k<n;k++) {
for(int j=0;j<s;j++) {
c[i][k]+=a[i][j]*b[j][k];
}
if(k==0)
System.out.print(c[i][0]);
else
System.out.print(" "+c[i][k]);
}
System.out.println();
}
}
}
/** Class for buffered reading int and double values */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}