• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Setting an index's boundaries

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I have to create a method that takes int index. I am getting testing errors, because the index must be set 'between zero, inclusive, and the number of vertices, exclusive.'

So far all I have is:



Im pretty lost on how to "set" the index. If you can help it would be appreciated. Thanks.
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to control the same at calling time... You need to make sure that passed index should be between 0 to index - 1 if index is 1 to index else
if index is starting from 0 then you can pass index directly
 
Jackson Daniels
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So should I make an if statement that basically says if index is >= number of vertices then return vertices[index].?
 
Tushar Goel
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no..

You can say like this:



or


 
Marshal
Posts: 27371
88
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jackson Daniels wrote:So should I make an if statement that basically says if index is >= number of vertices then return vertices[index].?



You could do that, but then you'd have to decide what to return if that test failed. I don't think that's what you're missing here, though. The way you "set" that parameter is by doing it before you call the method. An example which is simpler than Tushar's, a bit simpler anyway:



So here I have set the value of the parameter to 1. Of course I could have any kind of code at all which sets the value of the parameter, I could read it from the console or choose a random number or use a loop variable as per Tushar's examples. Does that help, or are we on the wrong track?
 
Bartender
Posts: 732
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have to create a method that takes int index.


This part has nothing to do with setting the index. So your comment

So should I make an if statement that basically says if index is >= number of vertices then return vertices[index].?

is in the right direction, but incorrect logic. What you need is something like this:
 
I'm full of tinier men! And a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic