Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find the smallest element in an array?

 
Nick Hallloran
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is to write a method that finds the smallest element in an array of integers. I have to use 1, 2,4,5,10,100,2,-22 to test the method. My program is able to compile but it wont run. If anyone could help it would be much appreciated.

Here is my code:

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program is able to compile but it wont run


What does that mean exactly? Errors, unexpected output? No output? You have to give more details. Also, do you really not indent your code? It makes it terribly difficult to read.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran it and it compile and run okay for me.

did you try(assuming compiler set up correctly)...

javac fileName.java
then..

java fileName?
 
Nick Hallloran
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
haha wow i cant believe i missed that one....Thanks Alot!
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Hallloran wrote:haha wow i cant believe i missed that one....Thanks Alot!


Missed what?
 
salvin francis
Bartender
Posts: 1280
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:
Nick Hallloran wrote:haha wow i cant believe i missed that one....Thanks Alot!


Missed what?


possibly:
"java fileName.java" instead of "java fileName"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic