I already have the code for the assignment below, but the code has an error in the driver class. Please help me fix it. The assignment: Make a recursive method for factoring an integer n. First, find a factor f, then recursively factor n / f. This assignment needs a resource class and a driver class. The resource class and the driver class need to be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code The code of the resource class: import java.util.ArrayList; import java.util.List; public class U10E03R { // Recursive function to // print factors of a number public static void factors(int n, int i) { // Checking if the number is less than N if (i <= n) { if (n % i == 0) { System.out.print(i + " "); } // Calling the function recursively // for the next number factors(n, i + 1); } } } The code of the driver class: public class U10E03D { public static void main(String args[]) { int N = 16; factors(N, 1); } } The error is shown in the picture I attached, please have a look at it.
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
I already have the code for the assignment below, but the code has an error in the driver class. Please help me fix it.
The assignment:
Make a recursive method for factoring an integer n. First, find a factor f, then recursively factor n / f. This assignment needs a resource class and a driver class. The resource class and the driver class need to be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code
The code of the resource class:
import java.util.ArrayList;
import java.util.List;
public class U10E03R
{
// Recursive function to
// print factors of a number
public static void factors(int n, int i)
{
// Checking if the number is less than N
if (i <= n) {
if (n % i == 0) {
System.out.print(i + " ");
}
// Calling the function recursively
// for the next number
factors(n, i + 1);
}
}
}
The code of the driver class:
public class U10E03D
{
public static void main(String args[])
{
int N = 16;
factors(N, 1);
}
}
The error is shown in the picture I attached, please have a look at it.
Step by step
Solved in 2 steps with 1 images