Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Треугольная последовательность
- public class Solution {
- public static String recursion(int n) {
- int sum = 0;
- int j = 0;
- // Базовый случай
- if (n == 1) {
- System.out.print("1");
- } else {
- for (int i = 1; sum < n; i++) {
- sum += i;
- j = i;
- }
- // Шаг рекурсии / рекурсивное условие
- System.out.print(recursion(--n) + " " + j);
- }
- return "";
- }
- public static void main(String[] args) {
- recursion(5); // вызов рекурсивной функции
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment