wood burning stoves 2.0
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to group?" Watch "How to group?" New topic

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: 15092

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
I agree. Here's the link: http://aspose.com/file-tools
subject: How to group?
It's not a secret anymore!