Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Main {
- private static int upperBound = 999999;
- private static int threadsCount = 3;
- private static int count = 0;
- public static void main(String[] args) throws InterruptedException {
- ArrayList<Thread> threads = new ArrayList<>();
- int delta = upperBound / threadsCount;
- for(int i = 0; i < threadsCount; i++){
- Thread thread = new LuckyThread(i * delta, (i + 1) * delta);
- threads.add(thread);
- thread.start();
- }
- for(int i = 0; i < threadsCount; i++)
- threads.get(i).join();
- System.out.println("Total: " + count);
- }
- static class LuckyThread extends Thread {
- int startIndex;
- int endIndex;
- LuckyThread(int startIndex, int endIndex){
- this.startIndex = startIndex;
- this.endIndex = endIndex;
- }
- @Override
- public void run() {
- int x = startIndex;
- while (x < endIndex) {
- x++;
- if ((x % 10) + (x / 10) % 10 + (x / 100) % 10 == (x / 1000)
- % 10 + (x / 10000) % 10 + (x / 100000) % 10) {
- System.out.println(x);
- count++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement