id/email
password
forgot password
about | help | done | prefs | create account
CodingBat code practice

Java > Logic-2 > noTeenSum
prev  |  next  |  chance

Given 3 int values, a b c, return their sum. However, if any of the values is a teen -- in the range 13..19 inclusive -- then that value counts as 0, except 15 and 16 do not count as a teens. Suggestion: decompose a separate "public int fixTeen(int n) {" below noTeenSum() that takes in an int value and returns that value fixed for the teen rule. In this way, you avoid repeating the teen code 3 times.

noTeenSum(1, 2, 3) → 6
noTeenSum(2, 13, 1) → 3
noTeenSum(2, 1, 14) → 3

...Save, Compile, Run

See also Java Example Code. Java help docs: If Boolean Logic | Strings | While and For Loops | Arrays and Loops


prev  |  next  |  chance   |  CodingBat  >  Logic-2

Forget It! -- delete my code for this problem 212.0

Copyright Nick Parlante 2006-10 - privacy