/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package collins.Multithreading;
import com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl;
import java.util.Arrays;
/**
*
* @author collins
*/
public class MatrixVektor implements Runnable{
//Instanzvariable fuer den Thread
private static Thread thread;
public MatrixVektor(){
this.thread = new Thread(this, "Matrix-Vektor-Multiplikation");
thread.start();
}
public static int[] matrixMultvektor(int[][] matrix, int[] vektor) {
int[] result = null;
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
result[i] += matrix[i][j] * vektor[j];
}
}
return result;
}
public static void main(String[] args) {
int[][] matrix = new int[][]{{1, 2}, {3, 4}};
System.out.println("Matrix: \n" + Arrays.deepToString(matrix));
//int[][] matrix = {{1,2},{3,4}};
int[] vektor = new int[]{2, 2};
System.out.println("Vektor: \n" + Arrays.toString(vektor));
int[] result = new int[2];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
//Berechnung
result[i] += matrix[i][j] * vektor[j];
}
}
System.out.println("Matrix * Vektor: \n" + Arrays.toString(result));
}
@Override
public void run() {
while(true){
System.out.println(this.thread.getName()+" running...");
try{
Thread.sleep(500);
}
catch(InterruptedException ie){
}
}
}
}Add a code snippet to your website: www.paste.org