Please make a the following programs into one.
Please make a the following
class Main {
static void number(int num) {
if (num < 17) {
return;
} else {
System.out.print(num + " ");
// call function recursively
number(num - 1);
}
}
public static void main(String[] args) {
Main r1 = new Main();
int num = 25;
r1.number(num);
class Main {
static void number(int num) {
if (num < 9) {
return;
} else {
System.out.print(num + " ");
// call function recursively
number(num - 2);
}
}
public static void main(String[] args) {
Main r1 = new Main();
int num = 25;
r1.number(num);
}
}
class Main {
static void number(int num) {
if (num > 18) {
return;
} else {
System.out.print(num + " ");
// call function recursively
number(num + 2);
}
}
public static void main(String[] args) {
Main r1 = new Main();
int num = 2;
r1.number(num);
}
}
class Main {
static void number(int num) {
if (num > 10) {
return;
} else {
System.out.print(num + " "); // call function recursively
number(num + 1);
}
}
// Main code
public static void main(String[] args) {
// Create an object
Main r1 = new Main();
int num = 2;
// call by reference variable
r1.number(num);
}
}
Step by step
Solved in 3 steps with 4 images