aspose file tools*
The moose likes Beginning Java and the fly likes Array of ten numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array of ten numbers" Watch "Array of ten numbers" New topic
Author

Array of ten numbers

Finbarrs Oketunji
Greenhorn

Joined: Dec 12, 2007
Posts: 5
Write a program to find the highest out of an array of ten numbers?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61430
    
  67

Sounds like fun. What have you tried so far?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Finbarrs Oketunji
Greenhorn

Joined: Dec 12, 2007
Posts: 5
Let's say I am a Newbie in JAVA that needs help with that and I have gone beyond the Hello World thing.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Finbarrs Oketunji
Greenhorn

Joined: Dec 12, 2007
Posts: 5
This is what I have been able to do:

Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3672
    
  15
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.


Joanne
Finbarrs Oketunji
Greenhorn

Joined: Dec 12, 2007
Posts: 5
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

Joined: Aug 05, 2005
Posts: 3672
    
  15
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

Joined: Dec 12, 2007
Posts: 5

That was the error it displayed.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11417
    
  16

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 ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array of ten numbers