简体   繁体   中英

How to solve error: ';' expected in Java?

I have a error: ';' expected 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 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()));
  }
}

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM