PROBLEM 52
Medium

Largest Digit

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#52

Given a positive three-digit integer, print its largest digit without using `Math.max()`.

EXAMPLE

Example

Input
583
Output
8

LIMITS

Constraints

100 ≤ n ≤ 999
📖
LEARN Theory for this problem
+

### Largest Digit

Integer division separates higher decimal/time units, while `%` returns the remainder. These two operations let a program isolate digits or split a total number of seconds/minutes into components.

💡
NEED HELP? Hints
+

['Decide which part comes from division and which part comes from the remainder.', 'Order the checks so a more specific case is not swallowed by a broader condition.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let n = Number(input);
let a = Math.floor((n) / (100));
let b = (((Math.floor((n) / (10))) % (10)) + (10)) % (10);
let c = (((n) % (10)) + (10)) % (10);
let m = a;
if (b > m) {
    m = b;
}
if (c > m) {
    m = c;
}
console.log(m);