I am having problems with the code in an else statement. I can’t figure out how to make recursively return 2 adjusted items in a list. I would appreciate any help.
public static int[] fibaux(int n) { if (n == 1) { return new int[] {1, 0}; } else { int[] array = new int[2]; list[] = {fibaux(n - 1)}; return //array[0] + array[1], array[1]; } }
In Java, multi-valued values are not allowed, i.e. you cannot return 2 values with return. You can simply return arraycontaining two values, for example:
return
array
return new int[] {num1, num2};
, , , . , , , , .
, :
public static int[] fibaux(int n) { if (n == 1) { return new int[] {1, 0}; } else { int[] array = fibaux(n - 1); return new int[] {array[0]+array[1], array[0]}; } }
Source: https://habr.com/ru/post/1628430/More articles:iOS app not showing static assets (images) after deployment - iosHow to change wallpapers suitable for UWP? - win-universal-appWhat is the difference between blob_url, raw_url and contents_url in the GitHub API? - gitAngular 2 allows the user to select and image from their local machine - angularMatplotlib value for numpy array image - pythonAny reason to declare constexpr for a function that returns void? - c ++A variable created inside a loop changes value during iterations in C - cКак отключить панорамирование левой кнопкой мыши в d3 - javascriptusing an alias for static member functions? - c ++How to get a hostname that contains a specific string from a group in Ansible - pythonAll Articles