java程序调用方法出现非法的表达式开始,怎么办 5
importjavax.swing.JOptionPane;publicclassMatrix{StringM=JOptionPane.showInputDialog("...
import javax.swing.JOptionPane;
public class Matrix {
String M=JOptionPane.showInputDialog("请输入a矩阵的行数");
String N=JOptionPane.showInputDialog("请输入a矩阵的列数"+
"或b矩阵的行数");
String S=JOptionPane.showInputDialog("请输入b矩阵的列数");
int m=Integer.parseInt(M);
int n=Integer.parseInt(N);
int s=Integer.parseInt(S);
public static void main(String[] args) {
int[][] a=new int[m][n];
int[][] b=new int[n][s];
int[][] c=new int[m][s];
enterMatrix(a,m,n);
enterMatrix(b,n,s);
printMatrix(a,m,n);
printMatrix(b,n,s);
MulMatrix(a,m,n,b,n,s,c);
printMatrix(c,m,s);
}
public static void enterMatrix(int[][] x, int row, int col) {
for(int i=0;i<row;i++) {
for(int j=0;j<col;j++) {
x[i][j]=(int)(Math.random() * 10);
}
}
public static void printMatrix(int[][] x, int row, int col) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
System.out.printf("%(row-1)d",x[i][j]);
}
System.out.println();
}
public static void MulMatrix(int[][] a, int rowa, int cola, int[][] b, int rowb,int colb,int[][] c)
{
for (int i = 0; i < rowa; i++) {
for (int j = 0; j < colb; j++) {
c[i][j] = 0;
for (int k = 0; k < cola; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
}
}
错在哪儿?怎么改? 展开
public class Matrix {
String M=JOptionPane.showInputDialog("请输入a矩阵的行数");
String N=JOptionPane.showInputDialog("请输入a矩阵的列数"+
"或b矩阵的行数");
String S=JOptionPane.showInputDialog("请输入b矩阵的列数");
int m=Integer.parseInt(M);
int n=Integer.parseInt(N);
int s=Integer.parseInt(S);
public static void main(String[] args) {
int[][] a=new int[m][n];
int[][] b=new int[n][s];
int[][] c=new int[m][s];
enterMatrix(a,m,n);
enterMatrix(b,n,s);
printMatrix(a,m,n);
printMatrix(b,n,s);
MulMatrix(a,m,n,b,n,s,c);
printMatrix(c,m,s);
}
public static void enterMatrix(int[][] x, int row, int col) {
for(int i=0;i<row;i++) {
for(int j=0;j<col;j++) {
x[i][j]=(int)(Math.random() * 10);
}
}
public static void printMatrix(int[][] x, int row, int col) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
System.out.printf("%(row-1)d",x[i][j]);
}
System.out.println();
}
public static void MulMatrix(int[][] a, int rowa, int cola, int[][] b, int rowb,int colb,int[][] c)
{
for (int i = 0; i < rowa; i++) {
for (int j = 0; j < colb; j++) {
c[i][j] = 0;
for (int k = 0; k < cola; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
}
}
错在哪儿?怎么改? 展开
3个回答
展开全部
import javax.swing.JOptionPane;
public class Matrix {
static String M = JOptionPane.showInputDialog("请输入a矩阵的行数");
static String N = JOptionPane.showInputDialog("请输入a矩阵的列数" + "或b矩阵的行数");
static String S = JOptionPane.showInputDialog("请输入b矩阵的列数");
static int m = Integer.parseInt(M);
static int n = Integer.parseInt(N);
static int s = Integer.parseInt(S);
public static void main(String[] args) {
int[][] a = new int[m][n];
int[][] b = new int[n][s];
int[][] c = new int[m][s];
enterMatrix(a, m, n);
enterMatrix(b, n, s);
printMatrix(a, m, n);
printMatrix(b, n, s);
MulMatrix(a, m, n, b, n, s, c);
printMatrix(c, m, s);
}
public static void enterMatrix(int[][] x, int row, int col) {
for(int i=0;i<row;i++) {
for(int j=0;j<col;j++) {
x[i][j]=(int)(Math.random() * 10);
}
}
}
public static void printMatrix(int[][] x, int row, int col) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
System.out.printf("%(row-1)d",x[i][j]);
}
System.out.println();
}
}
public static void MulMatrix(int[][] a, int rowa, int cola, int[][] b,
int rowb, int colb, int[][] c) {
for (int i = 0; i < rowa; i++) {
for (int j = 0; j < colb; j++) {
c[i][j] = 0;
for (int k = 0; k < cola; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
}
}
public class Matrix {
static String M = JOptionPane.showInputDialog("请输入a矩阵的行数");
static String N = JOptionPane.showInputDialog("请输入a矩阵的列数" + "或b矩阵的行数");
static String S = JOptionPane.showInputDialog("请输入b矩阵的列数");
static int m = Integer.parseInt(M);
static int n = Integer.parseInt(N);
static int s = Integer.parseInt(S);
public static void main(String[] args) {
int[][] a = new int[m][n];
int[][] b = new int[n][s];
int[][] c = new int[m][s];
enterMatrix(a, m, n);
enterMatrix(b, n, s);
printMatrix(a, m, n);
printMatrix(b, n, s);
MulMatrix(a, m, n, b, n, s, c);
printMatrix(c, m, s);
}
public static void enterMatrix(int[][] x, int row, int col) {
for(int i=0;i<row;i++) {
for(int j=0;j<col;j++) {
x[i][j]=(int)(Math.random() * 10);
}
}
}
public static void printMatrix(int[][] x, int row, int col) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
System.out.printf("%(row-1)d",x[i][j]);
}
System.out.println();
}
}
public static void MulMatrix(int[][] a, int rowa, int cola, int[][] b,
int rowb, int colb, int[][] c) {
for (int i = 0; i < rowa; i++) {
for (int j = 0; j < colb; j++) {
c[i][j] = 0;
for (int k = 0; k < cola; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
}
}
追问
非常感谢!没有了错误,可还是运行不出结果
追答
System.out.printf("%"+(row-1)+"d",x[i][j]);
展开全部
首先 你要把你的mns 都放到main里面 应为不能调用非static 的 还有你后面的几个方法缺少括号结尾 改过来就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
错在这里:System.out.printf("%(row-1)d",x[i][j]);
你想打印什么?
你想打印什么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询