1

I have a error: ';' expected issue with my Java code below. I don't know how to solve it?

SortThread and MergeThread have been created as a class, and compiled well.

The only problem is

SortThread t1.join() = new SortThread(a);  
SortThread t2.join() = new SortThread(b);  

MergeThread m.start() = new MergeThread(t1.get(),t2.get());

These three line codes has error: ';' expected issues.

In this main, it will create two array, a and b. m array will merge a&b, and main will display m.

Any hints or solutions are very helpful for me.

import java.util.Random;

public class Main{
    public static void main(String[] args){
       Random r = new Random(System.currentTimeMillis());

int n = r.nextInt(101) + 50;
int[] a = new int[n];
for(int i = 0; i < n; i++)
  a[i] = r.nextInt(100);

n = r.nextInt(101) + 50;
int[] b = new int[n];
for(int i = 0; i < n; i++)
  b[i] = r.nextInt(100);

SortThread t1.join() = new SortThread(a);  
SortThread t2.join() = new SortThread(b);  

MergeThread m.start() = new MergeThread(t1.get(),t2.get());

System.out.println(Arrays.toString(m.get()));
  }
}
2
  • 1
    You don't need to provide a seed like this, the built in one is better. Feb 8, 2016 at 2:26
  • I can't see the problem, start commenting lines out from the bottom until the problem goes away. Then you know that line is causing the trouble. Feb 8, 2016 at 3:10

1 Answer 1

3

You can't call the methods before you finish initializing the variables you're calling.

SortThread t1.join() = new SortThread(a);  
SortThread t2.join() = new SortThread(b);  

MergeThread m.start() = new MergeThread(t1.get(),t2.get());

should be something like

SortThread t1 = new SortThread(a);  
t1.start(); // <-- you probably want to start before you join.
SortThread t2 = new SortThread(b);
t2.start();  
t1.join();
t2.join();
MergeThread m = new MergeThread(t1.get(),t2.get());
m.start();
m.join();
1
  • for start() and join(), compiler says error: cannot find symbol
    – Wei Xia
    Feb 8, 2016 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.