0

I'm trying to Make two calls to a second return method which takes in one parameter ( my value in inches) and prints the value in centimeters but its not working! What did I do wrong?`

public static void main(String[] args) {
     Scanner in = new Scanner(System.in);

     // prompt the user and get the value
     System.out.print("Exactly how many inches are you?  ");
     int uHeight = in.nextInt();

    // converting and outputing the result
    System.out.print("How many inches is your mother? ");
    int mHeight = in.nextInt();
    InchesToCm(mHeight,uHeight);
}  

public static double InchesToCm() {


Scanner in = new Scanner(System.in);
System.out.print("Exactly how many inches are you?  ");
int inHeight = in.nextInt();
double cmHeight = inHeight * 2.54;
System.out.println("He's " + uHeight + " inches or " + mHeight + " cm.");
return
2
  • 1
    Please be more precise, how is it not working ? Commented Mar 17, 2017 at 9:40
  • 1
    What is the problem, the exception, the error ? Please edit the question with that information. See How to Ask. Well, I dont see a return value in the InchesToCm method but no closing bracket either .. so is it the complet method ? Commented Mar 17, 2017 at 9:40

1 Answer 1

3

You should to pass your mHeight and uHeight, in your method because you call it in your main method like this InchesToCm(mHeight,uHeight); so your method should look like this:

public static double InchesToCm(int mHeight, int uHeight) {//pass your values in method

Second you have to return the result in the end :

return cmHeight;//return the result

Note

For the good practice your methods should start with a lowercase letter like @Timothy Truckle said in comment and your class names should start with an upper letter


EDIT

For the good practice your have to use :

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.print("Exactly how many inches are you?  ");
    int uHeight = in.nextInt();

    System.out.println("He's " + uHeight + " inches or " + inchesToCm(uHeight) + " cm.");
    System.out.print("How many inches is your mother? ");

    int mHeight = in.nextInt();
    System.out.println("He's " + mHeight + " inches or " + inchesToCm(mHeight) + " cm.");
    //------------------------------^^-------------------------------^^------------------
    in.close();//close your Scanner
}

//Your function should take inches and return cm
public static double inchesToCm(int height) {
    return height * 2.54;
}
Sign up to request clarification or add additional context in comments.

5 Comments

and InchesToCm should start with a lowercase letter and a verb: convertInchesToCm
I need to make to Make two calls to a second return method which takes in one parameter ( my value in inches) and prints the value in centimeters
will changing it to lower case effect it?
you should point out that double inchesToCm(int mHeight, int uHeight) don't make sense. It is a utility function that should get one int and return a double. No scanner needed in there. And off course, the Scanner should be closed in the method but this will bring a lot of problem ;) EDIT : PERFECT :) except that the good practice should close the Sscanner ;)
@YCF_L, this happen a lot ;) I try to edit as fast as possible in that case, but maybe I should simply quickly add a editing ... to notify that I am adding information. And you are welcome, as always.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.