Question: Rewrite this code WITHOUT arraylists (you can use arrays, though) and comment the code properly. import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class CommomFactor {
Rewrite this code WITHOUT arraylists (you can use arrays, though) and comment the code properly.
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class CommomFactor {
public static List getCommonDivisor(int num1, int num2) {
List list = new ArrayList();
int min = minimum(num1, num2);
for (int i = 1; i
if (num1 % i == 0 && num2 % i == 0) {
list.add(i);
}
}
if (num1 % min == 0 && num2 % min == 0) {
list.add(min);
}
return list;
}
public static int minimum(int num1, int num2) {
return num1
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter two numbers : ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
List commonDivisor = getCommonDivisor(num1, num2);
System.out.println("Common factors : ");
for (int i = 0; i
System.out.print(commonDivisor.get(i) + " ");
}
}
Common Factors (5 points) Instructions Write a program that has a method called commonFactors. It takes in two integers and prints out the common factors of these two numbers. For example, if the numbers are 70 and 30 the program will print: 1 2 5 10 In the main method, use a Scanner object to read in two numbers (integers). Call the method commonFactors and pass in the two read numbers. Details Input Two integers Output The common factors Example Sample Input Sample Output 70 30 125 10 Problem2 Check It RUN ON TERMINAL
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
