W
Wrigleys
Also ich hab ein Problem mit der Ausgabe und weiß echt nicht was falsch ist.
Es zeigt mir meine Matrizen nicht wieder an, obwohl ich die davor eingegeben habe,
-----------------------------------------------------------------------------------------------------------------------
Es zeigt mir meine Matrizen nicht wieder an, obwohl ich die davor eingegeben habe,
-----------------------------------------------------------------------------------------------------------------------
Code:
Please write the matrix, Coloumn and Rows
Colomns:
2
Rows:
2
Creating Matrixes
Please Enter next: (0)(0)
1
Debug: setting value X2 Y2
Please Enter next: (0)(1)
1
Debug: setting value X2 Y2
Please Enter next: (1)(0)
1
Debug: setting value X2 Y2
Please Enter next: (1)(1)
1
Debug: setting value X2 Y2
[ 0.0 0.0 ]
[ 0.0 0.0 ]
null
[ 0.0 0.0 ]
[ 0.0 0.0 ]
null
[ 0.0 0.0 ]
[ 0.0 0.0 ]
null
-----------------------------------------------------------------------------------------------------------------------
//import java.util.*;
class Matrix {
static int x, y; //important, because you have to read the matrix
static String s; //important, because my InteractivIO wants a STRING!
static double [][]matrix; //important for the matrix (2dimensions [m=rows][n=coloms])
//----------------------------------------------------------------------------------------------
Matrix (int m, int n)throws Exception { //create a M-by-N matrix
x=m;
y=n;
matrix = new double [m][n];
}
//--------------------------------------------------------------------------------------------
public String toString() {
printMatrix(matrix);
return s;
}
public void printMatrix(double [][]matrix){
int m = matrix.length; //Rows
System.out.println();
for(int i=0; i<m; i++){
int n = matrix[i].length;
System.out.print("[ ");
for(int j=0; j<n; j++){
System.out.print(matrix[i][j]+" ");
}
System.out.println("]");
}
}
//--------------------------------------------------------------------------------------------
public double setElement(int i, int j, double k)throws Exception{
System.out.println("Debug: setting value X" + x + " Y" + y);
return matrix[i][j] = k;
}
//--------------------------------------------------------------------------------------------
public double getElement(int i, int j){
return matrix[i][j];
}
//---------------------------------------------------------------------------------------------
public void add (Matrix mat){
}
//--------------------------------------------------------------------------------------------
public void multiply(Matrix mat){
}
//--------------------------------------------------------------------------------------------
public static void main (String[]args) throws Exception {
Matrix A,B; //for the matrix
Matrix C; //for addition result matrix
InteractivIO.write("Please write the matrix, Coloumn and Rows");
y=InteractivIO.readInt("Colomns: ");
x=InteractivIO.readInt("Rows: ");
System.out.println("Creating Matrixes");
A= new Matrix(x,y);
B= new Matrix(x,y);
for(int i=0;i<x;i++){
for(int j=0;j<y; j++)
A.setElement(i,j,InteractivIO.readInt("Please Enter next: (" + i + ")(" + j + ")"));
}
C= new Matrix(x,y);
InteractivIO.write(A.toString());
InteractivIO.write(B.toString());
InteractivIO.write(C.toString());
}
}//end