如何解决错误:';' 预计在 Java 中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35261567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 16:29:04  来源:igfitidea点击:

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

java

提问by Wei Xia

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

我的error: ';' expected下面的 Java 代码有问题。不知道怎么解决?

SortThreadand MergeThreadhave been created as a class, and compiled well.

SortThread并且MergeThread已经创建为一个类,并且编译得很好。

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: ';' expectedissues.

这三行代码有error: ';' expected问题。

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

在这个 main 中,它将创建两个数组,a 和 b。m 数组将合并 a&b,而 main 将显示 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()));
  }
}

采纳答案by Elliott Frisch

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