아래 스레드 예제를 작성했는데..
작동이안되네요...
[3][2] * [2][3] 행렬 문제인데 스레드 써서 할려고 했는데 안되여..
어떻게 고쳐야 하나요?
더좋은 방법이나 이거 실행가능하게 하려면 어떻게 해야 할까요???ㅜ
class MyRunnable implements Runnable
{
int [][]A = {{1,2},{3,4},{5,6}};
int [][]B = {{1,2,3},{2,4,2}};
int [][]C;
int i ; // Rows
int j ; // Col
public void run(){
for ( i = 0 ; i3 ; i++){
for ( j = 0 ; j3 ; j++)
for (int n=0 ; n2 ; n++)
C[i][j] = A[i][n] * B[n][j];
System.out.println(C[i][j]);
}
}
}
public class ThreadMain {
public static void main (String[] args) {
// TODO Auto-generated method stub
Runnable threadJob = new MyRunnable();
Thread myThread = new Thread(threadJob);
myThread .start();
}
}
초록이 2026.08.31
int [][]C가 null이네요...
int [][]C = new int[3][3];으로 선언해주세요..
그리고 System.out.println(\C[i][j]\);
가 이런식이면
C[i][j]란 글자만 반복해서 나옵니다.
run() 메소드를 이렇게 고쳐주세요
public void run(){
for ( i = 0 ; i3 ; i++){
for ( j = 0 ; j3 ; j++)
for (int n=0
은아 2026.08.31
에러가 뭐라고나와용?
당나귀 2026.08.31
그건 안되네요......ㅠㅠ
비 2026.08.31
Thread myThread = new Thread(threadJob);
를
Thread myThread = new Thread(threadJob.run());
이렇게 해야하지 않나요?
맞나?