Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m making a program for an assignment and I keep getting errors. Can you tell

ID: 3545744 • Letter: I

Question

I'm making a program for an assignment and I keep getting errors. Can you tell me where I went wrong and an explanation on how I should go about fixing it? Thanks!

Here is my code:
import java.util.Scanner;

public class commondenonimator {
public static void main(String[] args) {

System.out.println("Find the Greatest Common Denominator of 3 numbers");

// Collect the 3 numbers to calculate GCD
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your first number");
int num1 = scanner.nextInt();// collect first number

System.out.println("Enter the second number");
int num2 = scanner.nextInt(); // collect second number

System.out.println("Enter the last number");
int num3 = scanner.nextInt();// collect the last number

//output
System.out.println("The common denominator for " + num1 + " , " + num2 + " and " + num3 + " is " + getGCD);

}

private int getGCD(int num1, int num2, int num3) {
getGCD(num1, num2, num3) = getGCD(getGCD(num1,num2),num3);
}
}

I'm making a program for an assignment and I keep getting errors. Can you tell me where I went wrong and an explanation on how I should go about fixing it? Thanks!

Here is my code:
import java.util.Scanner;

public class commondenonimator {
public static void main(String[] args) {

System.out.println("Find the Greatest Common Denominator of 3 numbers");

// Collect the 3 numbers to calculate GCD
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your first number");
int num1 = scanner.nextInt();// collect first number

System.out.println("Enter the second number");
int num2 = scanner.nextInt(); // collect second number

System.out.println("Enter the last number");
int num3 = scanner.nextInt();// collect the last number

//output
System.out.println("The common denominator for " + num1 + " , " + num2 + " and " + num3 + " is " + getGCD);

}

private int getGCD(int num1, int num2, int num3) {
getGCD(num1, num2, num3) = getGCD(getGCD(num1,num2),num3);
}
}

Explanation / Answer

Answer



You are missing the meat - the getGCD(int, int)

public class x {
public static void main(String[] args) {
int num1 = 100;
int num2 = 25;
int num3 = 50;

int getGCD = getGCD(num1, num2, num3);

System.out.println("The common denominator for " + num1 + " , " + num2 + " and " + num3 + " is " + getGCD);
}

private static int getGCD(int num1, int num2, int num3) {
return getGCD(getGCD(num1,num2),num3);
}

private static int getGCD(int num1, int num2) {
for (int x=num2; x>0; x--) {
if (num1 % x == 0 && num2 % x == 0) {
return x;
}
}

return 0;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote