L-S
L-S

Reputation: 119

Problems with a Simple Array

I'm writing a very simple method for my programming class and ran in to an issue I can't find the resolution for in my notes.

You see I'm supposed to create a method that generates an array of an arbitrary length that has each consecutive value be a multiple of the last (interest rates). The problem is I can't find why my code doesn't work, it compiles but doesn't print what I'd like.

Instead of printing an array with something like (made up values):

[1, 5, 25, 125]

It prints out obscure text like:

[D@64bd4e3c or [D@7041a12f 

Can someone please help? Below is a link to an image of my code:

My Code

My Code

Upvotes: 1

Views: 155

Answers (2)

Lews Therin
Lews Therin

Reputation: 10995

System.out.print(Statements)

is essentially System.out.println(Statements.toString()) ;

It prints the address that Statements points to.

[D@64bd4e3c" or "[D@7041a12f" As you may have observed changes because the location of the array in memory changes. Hence the address is different or may be the same if reused.

You need to iterate through Statements.

In pseudocode:

for i to Statements.length
  print Statements[i]

Here is a nice link to help you.

Upvotes: 7

Anand V
Anand V

Reputation: 124

For printing arrays in java, use:

System.out.println(java.util.Arrays.toString(Statements));

Hope this helps!

Upvotes: 4

Related Questions