This commit is contained in:
2026-03-15 20:40:00 +05:00
parent 06a34a1406
commit 775b21a9c4
5 changed files with 100 additions and 0 deletions

14
lr9/task_1/e1.java Normal file
View File

@@ -0,0 +1,14 @@
import java.util.Scanner;
class Main {
public static void m(int x){
System.out.println("x = " + x);
if ((2 * x + 1) < 20){
m(2 * x + 1);
}
}
public static void main(String[] args) {
m(1);
}
}

14
lr9/task_1/e2.java Normal file
View File

@@ -0,0 +1,14 @@
import java.util.Scanner;
class Main {
public static void m(int x){
if ((2 * x + 1) < 20){
m(2 * x + 1);
}
System.out.println("x = " + x);
}
public static void main(String[] args) {
m(1);
}
}

25
lr9/task_1/e3.java Normal file
View File

@@ -0,0 +1,25 @@
import java.util.Scanner;
class Main {
private static int step = 0;
public static void m(int x){
space();
System.out.println("" + x + "-> ");
step++;
if ((2 * x + 1) < 20){
m(2 * x + 1);
}
step--;
space();
System.out.println("" + x + " <-");
}
public static void space(){
for (int i = 0; i < step; i++){
System.out.println(" ");
}
}
public static void main(String[] args) {
m(1);
}
}

15
lr9/task_1/e4.java Normal file
View File

@@ -0,0 +1,15 @@
import java.util.Scanner;
class Main {
public static void main(String[] args) {
System.out.println(fact(5));
}
public static int fact(int n){
int res;
if (n == 1) return 1;
else{
res = fact(n - 1) * n;
return res;
}
}
}

32
lr9/task_1/e5.java Normal file
View File

@@ -0,0 +1,32 @@
import java.util.Scanner;
class Main {
public static void main(String[] args) {
int result = fact(5);
System.out.println("Результат: " + result);
}
public static int fact(int n) {
System.out.println("Вход в fact(" + n + ")");
if (n == 0) {
System.out.println("fact(0) -> 0");
return 0;
}
else if (n == 1) {
System.out.println("fact(1) -> 1");
return 1;
}
else {
int a = fact(n - 2);
int b = fact(n - 1);
int result = a + b;
System.out.println("fact(" + n + ") = fact(" + (n-2) + ") + fact(" + (n-1) + ") = " + result);
return result;
}
}
}