patrj
BAN USERThere are no APIs as such to my knowledge. But this can be achieved
1. With the example given by Nelson Perez
2. Write the timestamp and the thread name in logs.
3. You can make threads execute in sequence with priority assignments
4. You can also make threads execute in sequence, putting other threads in sleep.
We don't need to create the list even to get the nth number, following code works without the having to create the list:
public static void main(String[] args) {
int multipleOfTwo = 2, factorTwo = 1;
int multipleOfThree = 3, factorThree = 1;
int multipleOfFive = 5, factorFive = 1;
int n = 10;
int finalNumber = 1;
while (n > 1) {
finalNumber = Math.min(multipleOfTwo * factorTwo,
Math.min(multipleOfThree * factorThree, multipleOfFive * factorFive));
if (finalNumber == multipleOfTwo * factorTwo) {
factorTwo++;
}
if (finalNumber == multipleOfThree * factorThree) {
factorThree++;
}
if (finalNumber == multipleOfFive * factorFive) {
factorFive++;
}
n--;
}
System.out.println(finalNumber);
}
- patrj March 04, 2015
Simple solution: Use MinHeap.
- patrj March 07, 2015Add all the elements of first column to the heap and min heapify, print the root, remove and put the next from the same row. Repeat.