• Post Reply Bookmark Topic Watch Topic
  • New Topic

Call returned array from main method, to Void method  RSS feed

 
Samuel Norman
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So my other issue with my code, is I have everything in line, from main method, to average, array, and combining arrays methods. My last part is I need to call the combined array, which is returned to the main method, to the Public Static Void Display (int[] list)

i have tried putting in:

void [] sumList = dispArr(list);

and int[] sumList = dispArr(list):

How do I call or reference the returned value in the main method, to the Void method?
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like its a C# code?

Can you be more clear with your query?

From what I could gather, if your Display method is not returning any value, you cannot assign that method invocation to a variable.
 
Samuel Norman
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static void dispArr(int[] list)
{
for(int i = 0; i < 1; i++)
{
System.out.println("The array is: " + );
}
}
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("How many #'s do you want ?: ");
int x= input.nextInt();
int[] firstArray= inputArray(x);
{
System.out.println("The array is : " + java.util.Arrays.toString(firstArray));
}
double arrayAverage = average(listArr);
{
System.out.println("The average is: " + arrayAverage);
}
int[] addedArrays= add(firstArray, firstArray);

dispArr(firstArray);
}
}


Basically I am trying to take the combined array, which is the int[] addedArrays, and use that value in the Public Static Void dispArr (int[] list) . In earlier methods, which are not shown, I had an array formed by user inputs, and combined that array with another array. I now want the combined array value (for example, {34, 14, 25, 16} to be able to be called into the dispArr method, which that method has the command to print out the array. I can invoke the method, which you can see with:

dispArr(firstArray); but I know firstArray does not belong in here. How do I get the method to apply the combined array, and display them combined. firstArray displays the 1st array, combArrays if put in the parenthesis only adds the 1st two numbers and the rest are 0. But if i System.out.println combArrays in the main method, it comes out for the correct answer, the problem is I need to invoke the dispArr method which has the print command. Does that make sense?
 
Samuel Norman
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just solved, it thanks! I know I was probably confusing in explaining it, but I just had to assign and invoke the method correctly. I was over-complicating it.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If combArrays is the array you wish to output, have you tried calling the dispArr method, passing it instead?
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel

As a side note, consider your naming style for your code.

For example, something like displayArray is much clearer as a method name than dispArr.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!