Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Main {
  4.     private static int upperBound = 999999;
  5.     private static int threadsCount = 3;
  6.     private static int count = 0;
  7.  
  8.     public static void main(String[] args) throws InterruptedException {
  9.  
  10.         ArrayList<Thread> threads = new ArrayList<>();
  11.  
  12.         int delta = upperBound / threadsCount;
  13.         for(int i = 0; i < threadsCount; i++){
  14.             Thread thread = new LuckyThread(i * delta, (i + 1) * delta);
  15.  
  16.             threads.add(thread);
  17.  
  18.             thread.start();
  19.         }
  20.  
  21.         for(int i = 0; i < threadsCount; i++)
  22.             threads.get(i).join();
  23.  
  24.         System.out.println("Total: " + count);
  25.     }
  26.  
  27.     static class LuckyThread extends Thread {
  28.  
  29.         int startIndex;
  30.         int endIndex;
  31.  
  32.         LuckyThread(int startIndex, int endIndex){
  33.             this.startIndex = startIndex;
  34.             this.endIndex = endIndex;
  35.         }
  36.  
  37.         @Override
  38.         public void run() {
  39.  
  40.             int x = startIndex;
  41.             while (x < endIndex) {
  42.                 x++;
  43.                 if ((x % 10) + (x / 10) % 10 + (x / 100) % 10 == (x / 1000)
  44.                         % 10 + (x / 10000) % 10 + (x / 100000) % 10) {
  45.                     System.out.println(x);
  46.                     count++;
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement