Results 1 to 5 of 5
- 04-02-2012, 01:15 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Creating an array constructor and then creating an object in a main method
Hi,
I am new to programming and Java and get easily confused so any help is much appreciated.
I have created a constructor as follows:
private int [] myArray;
public MinInt (int [] setArray)
{
myArray = setArray;
}
I know want to use this constructor in my main method to create an array of integers but can't seem to get the syntax correct to declare this.
At the minute I have:
MinInt theArray = new MinInt {2,4,3,1,6,8};
But this does not work.
I know this is probably very simple.
- 04-02-2012, 01:42 PM #2
Re: Creating an array constructor and then creating an object in a main method
Define an array of ints
Pass the name of that array in the constructor.If you don't understand my response, don't ignore it, ask a question.
- 04-02-2012, 01:48 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: Creating an array constructor and then creating an object in a main method
So this would be correct?
int [] anArray = {3,76,2,33,76,24,65,9};
MinInt theArray = new MinInt (anArray);
- 04-02-2012, 01:49 PM #4
Re: Creating an array constructor and then creating an object in a main method
A good way to make sure would be to try it in the compiler.
If you don't understand my response, don't ignore it, ask a question.
- 04-02-2012, 01:50 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
Creating an object containing an array and int - small error
By treeface99 in forum New To JavaReplies: 3Last Post: 01-04-2012, 02:30 PM -
Creating and implementing class for creating a calendar object
By kumalh in forum New To JavaReplies: 9Last Post: 07-29-2011, 02:18 PM -
Creating a main method?
By Brainz in forum New To JavaReplies: 12Last Post: 11-16-2010, 10:56 AM -
No main method, constructor/object not working
By sinista in forum New To JavaReplies: 9Last Post: 10-14-2009, 02:25 PM -
Need help with creating array of type object
By riz618 in forum New To JavaReplies: 3Last Post: 01-29-2008, 06:14 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks