Defects per thousand parts
Quality control reports scrapped parts as so many per thousand produced, truncated down.
- The rate is defects per thousand, truncated down.
- A run that produced nothing has no rate: return 0.
defectsPerThousand(defects: int, produced: int) → int
Java needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
int defectsPerThousand(int defects, int produced) {
}
Worked examples
| Call | Result |
|---|---|
defectsPerThousand(500, 1000) | 500 |
defectsPerThousand(3, 10000) | 0 |
defectsPerThousand(1, 3) | 333 |
defectsPerThousand(2, 3) | 666 |
Hint
defects * 1000 / produced, guarding the divide by zero.
Reference solution in Java
int defectsPerThousand(int defects, int produced) {
if (produced <= 0) return 0;
return (defects * 1000) / produced;
}