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

 

jebbert@volusia.k12.fl.us > test2024_11_21_P1SLHL_sumBlockOf_n_Digits
prev  |  next  |  chance

IMPORTANT! You are NOT allowed to use ANY conditionals such as 'if', 'switch', or the ternary conditional. You are, however, allowed to use Boolean conditions in the headers of for loops or while loops. Write a method that returns the sum of the right-most two blocks of 'n' digits of the input parameter 'num'. Ignore any digits that are not in the right-most two blocks of digits. As preconditions, you may assume that 'a' will be non-negative, and that 'n' will be an integer between 1 and 6 inclusive. The previous sentences are hard to understand unless you see some examples, so here are some examples: If 'num' is 5123 and 'n' is 2 you would return 74. This is because the right-most block of 2 digits is 23 and the NEXT right-most block of two digits is 51. The sum of 23+51 is 74. If 'num' is 923124 and 'n' is 2 you would return 55. This is because you would add 24+31 which equals 55. You would ignore the 92 because you are only supposed to use the right-most two blocks of 2 digits. If 'num' is 7234111 and 'n' is 3 you would return 345. This is because you would add 234+111 which equals 345. You would ignore the 7 because you are only supposed to use the right-most two blocks of 3 digits.


test2024_11_21_P1SLHL_sumBlockOf_n_Digits(7234111, 3) → 345
test2024_11_21_P1SLHL_sumBlockOf_n_Digits(87234, 2) → 106
test2024_11_21_P1SLHL_sumBlockOf_n_Digits(1272464, 5) → 72476

...Save, Compile, Run (ctrl-enter)

public int test2024_11_21_P1SLHL_sumBlockOf_n_Digits(int num, int n) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 250

Copyright Nick Parlante 2017 - privacy