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

 

amjadm@miamioh.edu project5 > isFinalPairEqual
prev  |  next  |  chance

You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits. For each pair of consecutive digits in s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10. Then replace s with the sequence of these new digits, keeping the order in which they were calculated. Return true if the final two digits in s are the same, otherwise return false. For example, if s = “3902”, the first operation gives “292” because (3+9)%10 = 2, (9+0)%10 = 9, and (0+2)%10 = 2. The second operation gives “11” because (2+9)%10 = 1 and (9+2)%10 = 1. Since the final two digits are both 1, the result is true. If s = “34789”, the steps are: “7157”, then “862”, then “48”. Since 4 is not equal to 8, the result is false. The input string will always have a length of at least 3 and at most 100 characters, and it will only contain digit characters.


isFinalPairEqual("3902") → true
isFinalPairEqual("34789") → false
isFinalPairEqual("999") → true

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

public boolean isFinalPairEqual(String s) { }

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: 305

Copyright Nick Parlante 2017 - privacy