Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Java help


  • Please log in to reply

#1
jaj2

jaj2

    New Member

  • Member
  • Pip
  • 5 posts
Write a function that prints (not returns!) the sum of all the numbers from 1 to 1000 that contain both the digit 1 and the digit 3. For example, your sum will include the numbers 351, 13, and 15983, but not 300, 11, or 927.
  • 0

Advertisements


#2
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
welcome back jaj2,

let's see if you can modify the code from your previous topic using indexOf() again.

from the last topic, s.indexOf( '7' ) returns -1 if '7' is not found
and s.indexOf( '7' ) returns a number greater than or equal to zero if
'7' is found.

hint: the line below needs to be modified to find '1' and '3'
if( s.indexOf( '7' ) == -1 )

also verify 'i <= 1000' is in your code(as below)
for( int i = 1;i <= 1000;i++ ) {

bdlt
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP