Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass the content of a 2D array from one method to another one?  RSS feed

 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing a project but all day long i run into a problem and i am trying to figure it out what is going wrong but i couldn't find a solution that's why i decided to ask help from others.

In class Threshold :


in Main Class:


Note: only part of the code which is neccessary for my problem is given above

Now the problem is when i call one.getPolynomialCoefficents i got one 2d array of elements 0.

What i want to take is the content of 2d array which is generated in this part of the code :


Should anyone tell me what i need to do to get back the content of 2D array after i call method getPolynomialCoefficents
 
Carey Brown
Bartender
Posts: 2994
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question is a little vague but let me give it a shot.



Not sure why you chose bytes. Looks like int's might have been a better choice.
 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This solution does not solve my problem . I still got one 2d array with all its elements zero. The problem is i think to the variable scope but on the other hand i use keyword this . I choose byte because i am working on GF(256) from -128 to 127 thats why
 
Carey Brown
Bartender
Posts: 2994
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
barlet south wrote: This solution does not solve my problem . I still got one 2d array with all its elements zero. The problem is i think to the variable scope but on the other hand i use keyword this . I choose byte because i am working on GF(256) from -128 to 127 thats why

This is the only place where you assign to any array element, otherwise, they're initialized to zero.
 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please demonstrate it by writing the code
 
Carey Brown
Bartender
Posts: 2994
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 55715
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays.fill(myArray[0], 42);
Arrays.fill(myArray, myArray[0]);

Suitable for rectangular arrays only.
 
barlet south
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is not to fill this 2d array , the problem is that i am not able to take back the content of the array to the method getPolynomialCoefficents().
What i got here is an array with all its elements 0
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without the full code it's hard to debug.

Is this a typo? (missing final ";") private byte [] [] arrayOfRandomNumbers
 
Carey Brown
Bartender
Posts: 2994
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Without the full code it's hard to debug.

I also think what you have shown us is pretty messy. I suggest putting this code aside temporarily and work on a program that initializes an array, prints it, passes it, and prints it again. Maybe that would give you some insights in to how to clean up your code.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to post the full code, I would search for the variable arrayOfRandomNumbers. Is it getting initialized somewhere else?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!