Hi everybody I'm extremely new to java programming and was asked to do this >
" The formula for finding the greatest common divisor of two positive integers x and y
follows the Euclidean algorithm as follows:
1. Subtract x from y repeatedly until y < x.
2. Swap the values of x and y.
3. Repeat steps 1 and 2 until x = 0.
4. y is the greatest common divisor of the two numbers.
•
Place the calculation for finding the divisor in a static method. You can use one loop
for step 1 of the algorithm nested within a second loop for step 3.
•
Assume that the user will enter valid integers for both numbers.
•
The application should continue only if the user enters “y” or “Y” to continue. "
Problem is, I can't figure out how to do that. I'm trying the best I can but it says it doesn't work. Can you tell me how to fix it?
Here's what's specifically wrong with it
1. Illegal start of expression , cannot find symbol, symbol class : class first number, location: class Greatest common division finder.
2. Illegal start of expression, cannot find symbol, symbol class : class second number, location : class Greatest common division finder.
3. int Greatestcommondivisionfinder = 0; < The assigned value is never used
4. public static int Greatestcommondivisionfinder(firstNumber, secondNumber){ <identifier expected>
package greatest.common.division.finder; import java.util.Scanner; import java.math.*; /** * * Marcus Davis */ public class GreatestCommonDivisionFinder { /** * @param args the command line arguments */ public static void main(String[] args) { // welcome the user to the program System.out.println("Greatest Common Division Finder"); System.out.println(); // print a blank line //create a Scanner object and start a while loop Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { //get input from user System.out.print("Enter first number: "); int firstNumber = sc.nextInt(); System.out.println("Enter second number: "); int secondNumber = sc.nextInt(); } //create static method int secondNumber = 0; int firstNumber = 0; int Greatestcommondivisionfinder = 0; /** * */ public static int Greatestcommondivisionfinder(firstNumber, secondNumber){ //subtract firstnumber from secondnumber int secondNumber = 0; int firstNumber = 0; int Greatestcommondivisionfinder = 0; if (firstNumber > secondNumber) { secondNumber -= firstNumber; firstNumber--; } else if (firstNumber <= secondNumber) { firstNumber -= secondNumber ; } if (secondNumber == 0); { Greatestcommondivisionfinder = (firstNumber); } //Display GreatestCommondivisionfinder String message = "Greatest Common Division Finder:" + Greatestcommondivisionfinder + "\n"; System.out.println(message); return Greatestcommondivisionfinder; }
Any suggestions???