Need help!!

Discussion in 'Java' started by Marcusjamaal, Oct 9, 2012.

  1. Marcusjamaal

    Marcusjamaal

    Joined:
    Oct 9, 2012
    Messages:
    2
    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;
    }





    }
    }
    Marcusjamaal, Oct 9, 2012
    #1
    1. Advertising

  2. Marcusjamaal

    Marcusjamaal

    Joined:
    Oct 9, 2012
    Messages:
    2
    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>
    Marcusjamaal, Oct 9, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TN Bella
    Replies:
    1
    Views:
    2,471
    Edward
    Jun 18, 2004
  2. Teep
    Replies:
    2
    Views:
    765
    Larry Marburger
    Jun 21, 2004
  3. John
    Replies:
    1
    Views:
    394
    John C. Bollinger
    Aug 19, 2004
  4. =?Utf-8?B?Q2hyaXM=?=

    Help Help. I really need some help with this

    =?Utf-8?B?Q2hyaXM=?=, Jan 31, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    559
    =?Utf-8?B?SmFzb24gVmVybWlsbGlvbg==?=
    Jan 31, 2007
  5. ElementX
    Replies:
    9
    Views:
    490
    RedGrittyBrick
    Oct 1, 2008
Loading...

Share This Page