Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Java help

  • Please log in to reply



    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





  • 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++ ) {

  • 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