• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Array of ten numbers

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a program to find the highest out of an array of ten numbers?
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like fun. What have you tried so far?
 
Finbarrs Oketunji
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's say I am a Newbie in JAVA that needs help with that and I have gone beyond the Hello World thing.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Finbarrs Oketunji:
Let's say I am a Newbie in JAVA that needs help with that and I have gone beyond the Hello World thing.


Then this sounds like a great exercise!

Do you know how to create the array? Can you describe a general process for finding that largest number?
 
Finbarrs Oketunji
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I have been able to do:

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're trying to assign an int array to an int variable. Instead you should initialise the 'largest' variable to the first value in the array


Java is also case sensitive - 'For' should be 'for'

Make those changes and then if you are still having problems, post your new code and tell us what the problems are - if it doesn't compile show the error messages. If it doesn't work as you expect, tell us what it is doing and why this isn't what you want it to do.
 
Finbarrs Oketunji
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I included it but it isn't still compiling so I re-wrote another one to give an output of the highest number the same thing keeps occurring, help will be welcomed:

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tell us what the problems are - if it doesn't compile show the error messages. If it doesn't work as you expect, tell us what it is doing and why this isn't what you want it to do.
 
Finbarrs Oketunji
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

That was the error it displayed.
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that's telling you that the jvm doesn't know what the variable 'numNames' is in the place where you are using it.

Variables in java have what is called "scope" - they are not universally available anywhere in the code.

BASICALLY, a variable's scope is the set of curly brackets where it is defined. so, taking your code...



Since your variable is defined inside the main() method, that is the only place you can use it. You can make it a class variable, and then refer to it anywhere in the class, or you could pass it into the method.
[ December 13, 2007: Message edited by: Fred Rosenberger ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic