CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Java help !!

  1. #1
    Join Date
    Aug 2009
    Posts
    10

    Unhappy Java help !!

    i want to a method to return an integer value and print it outside the method

    here is my code

    public class returnvariable{

    public static void main (String[] args) {

    public int getFloor(){
    int currentFloor = 2;
    return currentFloor;
    }

    int curFloor = getFloor();

    System.out.println("Answer is: " + curFloor);

    }
    }

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Java help !!

    When posting code please use code tags (see the "before you post" thread) and if your code doesn't compile/run please post the error messages in full. It also helps if you ask a specific question, just saying what you want to do and posting code is generally not enough information.

    As to your problem- you've declared a method within another method which is illegal. You need to move the getFloor() method outside of the main() method.

    I also suggest you use standard Java naming conventions (Class names should start with a capital letter and use camel case) as it makes it easier for others to read your code.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured