import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
T1 a=new T1();
a.start();
T2 b=new T2();
b.start();
T3 c=new T3();
c.start();
T4 d=new T4();
d.start();
}
}
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class T1 extends Thread{
public void run()
{
int count=0;
for(int j=50000;j<=150000;j++)
{
int test=j;
int flag=0;
for(int i=2;i<test;i++)
{
if(test%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
count++;
}
}
FileOutputStream fou = null;
try {
fou = new FileOutputStream("C:\\2021JAVA\\上机考试模拟题2\\上机考试模拟题2\\A卷(考生姓名)\\DataA\\part1.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputStreamWriter ouw=new OutputStreamWriter(fou);
try {
ouw.write("50000-150000之间的素数为:");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String t=""+count+"个\r\n";
try {
ouw.write(t);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int j=50000;j<=150000;j++)
{
int test=j;
int flag=0;
for(int i=2;i<test;i++)
{
if(test%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
String t1=""+j+"\r\n";
try {
ouw.write(t1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
try {
ouw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class T2 extends Thread{
public void run()
{
int count=0;
for(int j=150001;j<=200000;j++)
{
int test=j;
int flag=0;
for(int i=2;i<test;i++)
{
if(test%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
count++;
}
}
FileOutputStream fou = null;
try {
fou = new FileOutputStream("C:\\2021JAVA\\上机考试模拟题2\\上机考试模拟题2\\A卷(考生姓名)\\DataA\\part2.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputStreamWriter ouw=new OutputStreamWriter(fou);
try {
ouw.write("150001-200000之间的素数为:");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String t=""+count+"个\r\n";
try {
ouw.write(t);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int j=150001;j<=200000;j++)
{
int test=j;
int flag=0;
for(int i=2;i<test;i++)
{
if(test%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
String t1=""+j+"\r\n";
try {
ouw.write(t1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
try {
ouw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class T3 extends Thread{
public void run()
{
int count=0;
for(int j=200001;j<=230000;j++)
{
int test=j;
int flag=0;
for(int i=2;i<test;i++)
{
if(test%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
count++;
}
}
FileOutputStream fou = null;
try {
fou = new FileOutputStream("C:\\2021JAVA\\上机考试模拟题2\\上机考试模拟题2\\A卷(考生姓名)\\DataA\\part3.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputStreamWriter ouw=new OutputStreamWriter(fou);
try {
ouw.write("200001-230000之间的素数为:");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String t=""+count+"个\r\n";
try {
ouw.write(t);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int j=200001;j<=230000;j++)
{
int test=j;
int flag=0;
for(int i=2;i<test;i++)
{
if(test%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
String t1=""+j+"\r\n";
try {
ouw.write(t1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
try {
ouw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class T4 extends Thread{
public void run()
{
int count=0;
for(int j=230001;j<=250000;j++)
{
int test=j;
int flag=0;
for(int i=2;i<test;i++)
{
if(test%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
count++;
}
}
FileOutputStream fou = null;
try {
fou = new FileOutputStream("C:\\2021JAVA\\上机考试模拟题2\\上机考试模拟题2\\A卷(考生姓名)\\DataA\\part4.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OutputStreamWriter ouw=new OutputStreamWriter(fou);
try {
ouw.write("230001-250000之间的素数为:");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String t=""+count+"个\r\n";
try {
ouw.write(t);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int j=230001;j<=250000;j++)
{
int test=j;
int flag=0;
for(int i=2;i<test;i++)
{
if(test%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
String t1=""+j+"\r\n";
try {
ouw.write(t1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
try {
ouw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}