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

 

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

You are given a string s. The score of the string is defined as the sum of the absolute differences between the ASCII values of every pair of adjacent characters. For example, if s = “hello”, the ASCII values of the characters are: h = 104, e = 101, l = 108, l = 108, o = 111. The score is calculated as |104 - 101| + |101 - 108| + |108 - 108| + |108 - 111| = 3 + 7 + 0 + 3 = 13. If s = “zaz”, the ASCII values are z = 122 and a = 97. The score is |122 - 97| + |97 - 122| = 25 + 25 = 50. You can assume the input string will contain at least two characters.


stringScore("hello") → 13
stringScore("zaz") → 50
stringScore("abc") → 2

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

public int stringScore(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