Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class GlobPER {
- public static int streams;
- public static int start = 100000000;
- }
- public class Main {
- public static void main(String[] args) {
- System.out.print("streams? - ");
- Scanner scan = new Scanner(System.in);
- int num = scan.nextInt();
- GlobPER.streams = num;
- int countMyThreadN = 0;
- long timeone = System.currentTimeMillis();
- MyThreadN [] threadN = new MyThreadN [num];
- int start = 100000000;
- for (int streams = 1; streams <= num; streams++)
- {
- int stop = start + 300000000 / num;
- if (streams == num){
- stop += 300000000 % num;
- }
- System.out.println(String.format("streams : %d",streams));
- threadN[streams-1] = new MyThreadN(start, stop);
- threadN[streams-1].start();
- start = stop;
- }
- for (int streams = 1; streams <= num; streams++){
- try {threadN[streams-1].join();}
- catch (InterruptedException e) {e.printStackTrace();}
- }
- long timetwo = System.currentTimeMillis();
- System.out.println("Time : " + (timetwo - timeone));
- }
- }
- class MyThreadN extends Thread {
- int start;
- int stop;
- MyThreadN(int startA, int stopA)
- {
- start = startA;
- stop = stopA;
- System.out.println(start + " " + stop);
- }
- // int countMyThreadN;
- @Override
- public void run() {
- int countMyThreadN = 0;
- for(int startA = start; startA < stop; startA++){
- if (startA%11==0 && startA%13==0 && startA%17==0 && startA%19==0) { countMyThreadN++; }
- }
- System.out.println(countMyThreadN);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement