-1

I'm trying to make a program in which an object is declared every time a loop is passed through.

package sequence;

public class SequenceServer {
    SequenceObj sequence = new SequenceObj();
    public void findSequence(int[] sequence, int lastNumber) {
        for(int i = 0; i < sequence.length; i++) {
            SequenceObj sequenceTemp = new SequenceObj(); // this line is wrong, but I don't know how to make it work
        }
    }
}

There are no errors, but I need to make it so a potentially infinite number of variables can be declared through the user interacting with the program, as opposed to me individually declaring all of the variables.

PaulD
  • 73
  • 1
  • 5

1 Answers1

0

Try this:

     `public class SequenceServer {
             SequenceObj sequence;
             public void findSequence(int[] sequence, int lastNumber) {
                      for(int i = 0; i < sequence.length; i++) {
                              sequence = new SequenceObj(); // this line is wrong, 
                         // but I don't know how to make it work
                      }
              }
         }`
A S M Sayem
  • 2,010
  • 2
  • 21
  • 28