📄 thread_experiment.java
字号:
/*ThreadTester is a class in which the running of the thread executes.
*/
import java.io.*;
public class ThreadTester
{
public static void main(String[] args)
{
if(args.length <= 0)
{
System.err.println("Usage: java ThreadTester <integer value>");
return;
}
else
{
Prime thrd = new Prime(Integer.parseInt(args[0]));
thrd.start();
}
}
}
/* Prime is a class in which the code for the thread exits. It prints out all prime number no greater than the given one.
*/
class Prime extends Thread
{
private int upper;
public Prime(int n)
{
upper = n;
}
public void run()
{
int i,j = 0;
if( upper < 0)
{
System.err.println("The number must be greater than 0!");
return;
}
else if(upper == 0 || upper == 1)
{
System.out.println("No prime numbers ... ");
}
else
{
for(i=2; i<=upper; i++)
{
for(j=2; j<i/2+1; j++)
{
if(i%j == 0)
break;
}
if(j >= i/2+1)
System.out.println(i);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -