我正在尝试创建多个线程,其数量取决于命令行的输入.我知道扩展Thread并不是最好的OO练习,除非你正在制作Thread的专用版本,但假设这个代码创建了所需的结果?
class MyThread extends Thread {
public MyThread (String s) {
super(s);
}
public void run() {
System.out.println("Run: "+ getName());
}
}
class TestThread {
public static void main (String arg[]) {
Scanner input = new Scanner(System.in);
System.out.println("Please input the number of Threads you want to create: ");
int n = input.nextInt();
System.out.println("You selected " + n + " Threads");
for (int x=0; x<n; x++)
{
MyThread temp= new MyThread("Thread #" + x);
temp.start();
System.out.println("Started Thread:" + x);
}
} …Run Code Online (Sandbox Code Playgroud) 在一行中使用两个赋值运算符时的操作顺序是什么?
public static void main(String[] args){
int i = 0;
int[] a = {3, 6};
a[i] = i = 9; // this line in particular
System.out.println(i + " " + a[0] + " " + a[1]);
}
Run Code Online (Sandbox Code Playgroud)
编辑:感谢您的帖子.我得到了=从右边获取值,但是当我编译它时,我得到:
9 9 6
Run Code Online (Sandbox Code Playgroud)
我认为它本来是和ArrayOutOfBounds异常,但它在它移动到9 之前分配'a [i]' 它是否只是为数组做那个?