JavaScript Algorithm Question: Positive Numbers
Enter 6 real numbers that are either positive or negative.
Please count and output the number of positive numbers.
input format
Six numbers, one on each line.
output format
The output format is x positive numbers
, where x is the number of positive numbers.
data range
The absolute value of the entered number does not exceed 100.
Input sample:
7
-5
6
-3.4
4.6
12
Sample output:
4 positive numbers
let buf = "";
process.stdin.on("readable", function() {
let chunk = process.stdin.read();
if (chunk) buf += chunk.toString();
});
process.stdin.on("end", function() {
let xs = buf.split('\n').map(x => {
return parseFloat(x)});
let res = 0;
for (let x of xs) {
if (x > 0)
res ++ ;
}
console.log(`${
res} positive numbers`);
});