#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    41
    Rep Power
    2

    Larger num using a method


    Ok here my current problem:
    Create a main class file. (1) Inside create a method max() that has two floating point
    parameters x and y and returns the larger of x and y; (2) In the main method, input two
    numbers from the keyboard, and then use the max() method you created to compute the
    larger value and output it.

    this is what i have the problem is that teoutput tends to be the second number entered not the larger of the two, not sure how to change that.






    import java.util.Scanner;
    public class LargerNum {
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("Enter two values: ");
    double FirstNum = input.nextDouble();
    double SecondNum = input.nextDouble();
    double Final = MaxMethod(FirstNum, SecondNum);



    }
    public static double MaxMethod(double L, double M){
    double Temp = L;
    double TempTwo = M;
    double Large;
    if (Temp >= TempTwo){
    Large = Temp;}
    else;

    Large = TempTwo;
    System.out.println(Large);
    return Large;

    }}
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    41
    Rep Power
    2
    import java.util.Scanner;
    public class LargerNum {
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("Enter two values: ");
    double FirstNum = input.nextDouble();
    double SecondNum = input.nextDouble();
    double Final = MaxMethod(FirstNum, SecondNum);



    }
    public static double MaxMethod(double L, double M){
    double Temp = L;
    double TempTwo = M;
    double Large;
    if (Temp >= TempTwo){
    Large = Temp;}
    else
    Large = TempTwo;
    System.out.println(Large);
    return Large;

    }}
    this code works but the println needs to be in the main method so how do i send the larger number determined in the maxmethod back to the main method for output?

IMN logo majestic logo threadwatch logo seochat tools logo