Need help!!

Joined
Oct 9, 2012
Messages
2
Reaction score
0
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?






/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
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;
}





}
}
 
Joined
Oct 9, 2012
Messages
2
Reaction score
0
zzhere are more specific reasons it says it can't work guys







1. Illegal start of expression , cannot find symbol, symbol class : class first number, location: class Greatest common division finder.




2. 2. Illegal start of expression, cannot find symbol, symbol class : class second number, location : class Greatest common division finder.




3. 3. int Greatestcommondivisionfinder = 0; < The assigned value is never used




4. 4. public static int Greatestcommondivisionfinder(firstNumber, secondNumber){ <identifier expected>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top