• Post Reply Bookmark Topic Watch Topic
  • New Topic

arrays in netbeans  RSS feed

 
laurie Watson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am stumped I get incapatable type found int required int[] same for the second line found double required double[] array dimention missing. I have tried adding a dimention i have tried taking the private away i have imported java.util.arraylist and Arrays and still have the same error message here is my code. I would be greatful for any help since i still have to have it pull the information from a text doc and add a pie chart but i am tring to do one step at a time. here's the code

private int[]terms = new int[](5,7,15,30,35);
private double[]interestRates = new double[](5,5.35,5.5,5.75,5.85);
Thanks in advance for any help. a frustrated newbee
 
KayCee Clark
Greenhorn
Posts: 13
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ditch the "new int[]" and change brackets to wavey versions

 
Vijitha Kumara
Bartender
Posts: 4002
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, laurie Watson!

And you can still use the syntax you used with the curly brackets...
 
Badal Chowdhary
Ranch Hand
Posts: 34
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can initialize your array in that way. It's more like a C++ style. KayCee's way is the only case in Java when you initialize an object without using the keyword new.

Check out http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html.


Is there a specific reason for choosing array over list?

Thanks,
Badal
 
KayCee Clark
Greenhorn
Posts: 13
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was a little terse, not explaining my self or welcoming you. My dog was "loudly" protecting us from the big bad door-to-door salesperson at the time.

This will work also
private int[] terms = new int[] {5,7,15,30,35};

but the new int[] are unnecessary if you have the initialization in the same statement.

Seems less cluttered to me.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Badal Chowdhary wrote: . . . KayCee's way is the only case in Java when you initialize an object without using the keyword new. . . .
Not quite. we get discussions about not using new every few months. Another way to create an object without saying new is like this:
 
Badal Chowdhary
Ranch Hand
Posts: 34
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell. Missed that. It is infact so commonly used.

Badal
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

There are other ways, but I'll let you search for the old threads, rather than trying to repeat them
 
Vijitha Kumara
Bartender
Posts: 4002
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Badal Chowdhary wrote:I don't think you can initialize your array in that way...

As already pointed out it's possible though you may not see that in a this kind of scenario. It's more commonly used in method calls where you need to initialize your array on the fly.

 
laurie Watson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks everyone it's a homework assignment and i am just getting frustrated. since there is more I have to do but wanted to figure this much out first before i moved on. I was just starting to enjoy the class when i hit this road block so I really appreciate the help

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!