Advertisement
fevzi02

Untitled

Feb 1st, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class GlobPER {
  4. public static int streams;
  5. public static int start = 100000000;
  6. }
  7.  
  8. public class Main {
  9. public static void main(String[] args) {
  10.  
  11. System.out.print("streams? - ");
  12. Scanner scan = new Scanner(System.in);
  13. int num = scan.nextInt();
  14. GlobPER.streams = num;
  15.  
  16.  
  17. int countMyThreadN = 0;
  18.  
  19. long timeone = System.currentTimeMillis();
  20. MyThreadN [] threadN = new MyThreadN [num];
  21. int start = 100000000;
  22. for (int streams = 1; streams <= num; streams++)
  23. {
  24. int stop = start + 300000000 / num;
  25. if (streams == num){
  26. stop += 300000000 % num;
  27. }
  28.  
  29. System.out.println(String.format("streams : %d",streams));
  30. threadN[streams-1] = new MyThreadN(start, stop);
  31. threadN[streams-1].start();
  32.  
  33. start = stop;
  34. }
  35. for (int streams = 1; streams <= num; streams++){
  36. try {threadN[streams-1].join();}
  37. catch (InterruptedException e) {e.printStackTrace();}
  38. }
  39.  
  40. long timetwo = System.currentTimeMillis();
  41.  
  42. System.out.println("Time : " + (timetwo - timeone));
  43. }
  44. }
  45.  
  46.  
  47. class MyThreadN extends Thread {
  48. int start;
  49. int stop;
  50.  
  51. MyThreadN(int startA, int stopA)
  52. {
  53. start = startA;
  54. stop = stopA;
  55. System.out.println(start + " " + stop);
  56. }
  57.  
  58. // int countMyThreadN;
  59. @Override
  60. public void run() {
  61.  
  62. int countMyThreadN = 0;
  63. for(int startA = start; startA < stop; startA++){
  64. if (startA%11==0 && startA%13==0 && startA%17==0 && startA%19==0) { countMyThreadN++; }
  65. }
  66. System.out.println(countMyThreadN);
  67. }
  68.  
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement