aspose file tools*
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 Spring in Action this week in the Spring 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: 14270
    
  21

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 8 API documentation
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to group?