This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to group? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to group?" Watch "How to group?" New topic
Author

How to group?

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Kind of a vague question, but didn't know how to ask it. Basically I have a this set of code, I posted the first 2 of 6, and I wanted to know how I would be able to reduce this into 1?

basically the code is EXACTLY the same besides f1,f2,f3,....,f6.




I figured I might be able to do something like f(n) or something like that, but I don't know.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Instead of having six variables f1, f2, f3, ..., f6 you could create an array.

Have a look at: The Java Tutorials - Arrays.

For example:

Access the six elements of the array as f[0], f[1], f[2], ..., f[5]. Ofcourse you can use a variable to index into the array:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to group?
 
Similar Threads
Comparison of arrays
Quw from KB book, chap 4 -> test Q 3
doubt in kathy sierra question?
Clrify results from SCJP mock exam site
hashing/bloom filter troubles