File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array of ten numbers

 
Finbarrs Oketunji
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a program to find the highest out of an array of ten numbers?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like fun. What have you tried so far?
 
Finbarrs Oketunji
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have been able to do:

 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That was the error it displayed.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic