This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

a way to get a name from an array  RSS feed

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys, i tried to write a code which returns the longest name in an array but i have 1 problem:
1.how do i set the "max" value that the compiler will read it and won't say " variable max might not have been initialized "?




Thank you !
 
Marshal
Posts: 24498
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know what it means to "initialize" a variable?
 
rian bron
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Do you know what it means to "initialize" a variable?


yes, but i want that my loop result will initialize its original value

lest say :
int x=0;
int y=10
for( int j=0;j<=y;j++)
    {
          x++;
    }

will i get here x=10?

int x=0;
int y=10
int returnX()
   {
for( int j=0;j<=y;j++)
    {
          x++;
    }
return x;
}

will i get here x=10?

Thank you
 
Ranch Hand
Posts: 186
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you are close

My suggestions for you is that you are going to be going through the array in linear time (sequentially). What I suggest is that you initialize the first value of the array to be the largest item prior to iterating through the array. Once you iterate or loop through the array, check every value against the max value and if it is larger than the max value, then that value would become the new max value. Good luck!
 
Let's go to the waterfront with this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!