class Entrance{ public static void main(String[] args) { Thread1 thread1=new Thread1(); thread1.start(); } } class Thread1 extends Thread{ public void run() { Thread2 thread2=new Thread2(); thread2.start(); } } class Thread2 extends Thread{ public void run() { System.out.println(20); } }
时间: 2024-04-10 20:31:35 浏览: 19
在上述代码中,主线程(即Entrance类的main方法)启动了Thread1线程,并开始执行Thread1的run方法。在Thread1的run方法中,创建了一个新的Thread2线程,并调用其start方法来启动Thread2线程。
由于Thread2的start方法是在Thread1线程中调用的,所以Thread2的run方法会在Thread2线程中执行。在Thread2的run方法中,打印输出了数字20。
总结起来,线程2的run方法会在线程2中执行,而不是在主线程或线程1中执行。
相关问题
The shaded part of the maze is the impassable location. Each position in the maze can explore the feasible path in 8 directions. Assuming that the exit position is at the bottom right corner (6, 8) and the entrance is at the top left corner (1, 1), it is required to design an algorithm to find a path from the entrance to the exit. Maze Problem • Input: The data of Maze,ends with 0 0 • Output: Yes or No. If there is a path from the entrance to the exit, output "Yes". Otherwise, output “No”. 8 10 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 1 1 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 0 0 0 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 6 8 Yes
Here's a Python solution to the maze problem using breadth-first search algorithm:
```python
from collections import deque
# read in the maze data
maze = []
while True:
row = list(map(int, input().split()))
if row == [0, 0]:
break
maze.append(row)
# set the start and end positions
start = (1, 1)
end = (6, 8)
# define the 8 possible directions
directions = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)]
# initialize the visited set and the queue for BFS
visited = set()
queue = deque([start])
# perform BFS
while queue:
current_pos = queue.popleft()
if current_pos == end:
print("Yes")
break
for d in directions:
next_pos = (current_pos[0] + d[0], current_pos[1] + d[1])
if next_pos[0] < 1 or next_pos[0] > len(maze) or next_pos[1] < 1 or next_pos[1] > len(maze[0]):
continue
if maze[next_pos[0]-1][next_pos[1]-1] == 0 or next_pos in visited:
continue
visited.add(next_pos)
queue.append(next_pos)
else:
print("No")
```
The program reads in the maze data from standard input, and then performs breadth-first search from the start position to find a path to the end position. The eight possible directions are defined in the `directions` list, and the visited positions are stored in the `visited` set. If the end position is reached, the program outputs "Yes". If the queue becomes empty and the end position is not reached, the program outputs "No".
east_entrance_data[i].drop_duplicates(subset='ID', keep='first',inplace=True)
这是一个 pandas DataFrame 对象调用的 drop_duplicates() 方法,它的作用是去除 DataFrame 中指定列(这里是 'ID')的重复行。其中,subset 参数指定要考虑的列名,keep 参数指定保留哪个重复行(这里是第一个出现的,即 'first'),inplace 参数指定是否在原 DataFrame 上进行修改(这里是 True,表示原地修改)。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)