• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to group?

 
Ranch Hand
Posts: 356
Android Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic