Results 1 to 4 of 4

Thread: Methods

  1. #1
    soccer_kid_6 is offline Member
    Join Date
    Feb 2010
    Posts
    35
    Rep Power
    0

    Default Methods

    As some of you saw my other thread creating methods. Well now I have created methods but I am having problems calling for it on the main method.

    These where the instructions from my instructor on how to create the method.
    Write a method called convertInchesToFeet

    * one parameter: inches
    * returns nothing
    * the method converts the number of inches to feet and inches
    * the method displays the result to the user
    o For example, if the method call sends 66 as the value of inches, say "Your are 5 feet and 6 inches tall"
    * notice you are outputing the information to the user from inside the method, not returning the value to main
    The code is
    Java Code:
    public static void convertinchestofeet(int inches)
    	{
    		int feet = inches / 12;
    		int pInches = inches % 12;
    		System.out.println("You are" + feet +"feet and" + pInches + "inches tall.");
    	}// end ConvertInchesToFeet Method
    Then the instructions for my main method are:
    says "Let's convert inches to feet" then

    * prints a blank line
    * Asks the user to enter the total number of inches tall he is
    * calls the convertInchesToFeet method
    my code is
    Java Code:
    public static void main(String[] args)
    	{
    Scanner scanner = new Scanner(System.in);
              System.out.println("Let's convert inches to feet\n");
    		System.out.print("Enter the total number of inches tall you are:");
    			int height = scanner.next();
    Now i have having trouble linking both methods and performing the actions my teachers asks for. Can anybody help me?

  2. #2
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    Umm, I'm pretty sure I already answered your question in the other thread.
    Classname.convertInchesToFeet(height);

  3. #3
    soccer_kid_6 is offline Member
    Join Date
    Feb 2010
    Posts
    35
    Rep Power
    0

    Default

    yeah but it aint working for me

  4. #4
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

Similar Threads

  1. Replies: 8
    Last Post: 04-17-2012, 12:00 AM
  2. Replies: 4
    Last Post: 04-03-2009, 07:36 AM
  3. Get and Set Methods
    By kian_hong2000 in forum New To Java
    Replies: 10
    Last Post: 08-27-2008, 03:06 PM
  4. methods
    By Zensai in forum New To Java
    Replies: 10
    Last Post: 12-03-2007, 06:31 AM
  5. Methods
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-01-2007, 09:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •