• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Still unable to call a method

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I understand it I should be able to call the method in the second part of the code using

printLargestAndSmallestElemnts();

I have been unsuccessful in finding a way to call the method that the compiler is happy with.

I'd appreciate being shown how to make the call. Code is below
 
Saloon Keeper
Posts: 15489
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you post code, please UseCodeTags. It'll make your problem much easier to understand. I added them for you this time.

I'm not quite sure what your main method is supposed to do. You first seem to be attempting to call the printLargestAndSmallestElements() method, which makes no sense because there's nothing yet to call it on. Even so, you should call it on a variable or a value, not on a variable declaration. To make it legal, remove the int[] part, and declare n before you make the method call.

You then declare n (which you should really do first) and "initialize" it by setting every element to 0. This is unnecessary, because an array always initializes all its elements to 0 or null when you create it.

If you're trying to create an array of random values, and then print the largest and smallest elements, you can do something like this:
 
Paul Roberts
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much. As you correctly point out, Line 9 shouldn't be there. Your suggestions gave me the momentum to find the solution.

You put the line printLargestAndSmallestElements(n); as the last instruction before the main method has finished and it works as

expected. I could have sworn I tried this solution at least three times during this sorry saga. I'm pleased I can continue with the

tutorial now and hopefully the experience will do me good.


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic