Return to Video

Sum Every Other Digit - Intro to Java Programming

  • 0:00 - 0:03
    Starting from the pseudo code from the hint video, and get
  • 0:03 - 0:07
    set to the credit card number. Sum is set to 0. Count
  • 0:07 - 0:10
    is also set to 0, and that's an int. And now
  • 0:10 - 0:13
    for the tricky part, for each digit in n starting from the
  • 0:13 - 0:16
    right. So I need to use the parts of this while
  • 0:16 - 0:20
    loop that correspond to that. So I'll keep while n is greater
  • 0:20 - 0:23
    than 0 and n equals n over 10. And I need
  • 0:23 - 0:26
    to actually get the digit so that I can add it. But
  • 0:26 - 0:28
    I don't just want to add the digit to the
  • 0:28 - 0:30
    sum. I only want to do that if count is
  • 0:30 - 0:33
    odd and I need to increment count. So count
  • 0:33 - 0:38
    plus, plus. And if count is odd then add digit
  • 0:38 - 0:44
    to the sum. But count is odd is not quite Java yet. If count mod 2 is 1
  • 0:44 - 0:48
    then count is odd. And instead of printing the
  • 0:48 - 0:51
    sum, I'll return it. And if I run the tester,
  • 0:51 - 0:55
    so far so good. I don't see any evidence that I made mistakes.
タイトル:
Sum Every Other Digit - Intro to Java Programming
概説:

more » « less
Video Language:
English
Team:
Udacity
プロジェクト:
cs046: Intro to Programming
Duration:
0:56

English subtitles

改訂 Compare revisions