如何解决错误:';' 预计在 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
How to solve error: ';' expected in Java?
提问by Wei Xia
I have a error: ';' expected
issue with my Java code below. I don't know how to solve it?
我的error: ';' expected
下面的 Java 代码有问题。不知道怎么解决?
SortThread
and MergeThread
have 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: ';' expected
issues.
这三行代码有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();