Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Code having problems please help - Invalid method declaration, return type required.

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Code having problems please help - Invalid method declaration, return type required.

    Hi,
    I have a code written in Java and the system is giving me an error "Invalid method declaration, return type required". Please help me to rectify this. Thanks.

    import java.io.*;
    class steve 
    {
    public static long perimeter_rectangle(int l,int b)
    {
    long x=2*(l+b);
    return x;
    }
    public static long perimeter_square(int s)
    {
    long a=4*s;
    return a;
    }
    public static void main (string args[]) throws IOException;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    {System.out.println("1=perimeter of rectangle");
    System.out.println("2=perimeter of square");
    System.out.println("ENTER YOUR CHOICE");}
    String str=br.readLine();
    int S=Integer.parseInt(str);
    Switch (S)
    {
    case 1:
    {
    System.out.println("enter the length n breadth");
    String l=br.readLine();
    int a=Integer.parseInt(l);
    String b=br.readline();
    int c=Integer.parseInt(b);
    long x=perimeter_rectangle(a,c);
    System.out.println(x);
    break;
    }
    case 2:
    {
    System.out.println("enter d side");
    String S=br.readLine();
    int q=Integer.parseInt(s);
    long a=perimeter_square(q);
    System.out.println(a);
    break;
    }
    default:
    System.out.println("INVALID CHOICE");
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Code having problems please help - Invalid method declaration, return type requir

    It helps to post the full error code otherwise you leave us guessing. My guess: java is case sensitive, and 'string' is not correct syntax for the main method.

    Edit: And one post is enough. I have deleted your other thread - please read the forum rules and know that double posting is not allowed
    Last edited by copeg; February 18th, 2012 at 11:10 AM.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Code having problems please help - Invalid method declaration, return type requir

    Hi,

    Can someone help in letting me know where the problem is in the Java code that I had put earlier in this thread. If 'string' is not a correct syntax, please let me know how I can get this script running fine as I am new to Java. Thanks.

    Quote Originally Posted by copeg View Post
    It helps to post the full error code otherwise you leave us guessing. My guess: java is case sensitive, and 'string' is not correct syntax for the main method.

    Edit: And one post is enough. I have deleted your other thread - please read the forum rules and know that double posting is not allowed

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Code having problems please help - Invalid method declaration, return type requir

    You need to post the full text of the error message that you are getting if you want help fixing the problem.

  5. #5
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Code having problems please help - Invalid method declaration, return type requir

    what theyre saying is try changing
    public static void main(string[] args){
    to

    public static void main(String[] args){

    Java is case sensitive, so watch out.

Similar Threads

  1. error: invalid meyhod declaration
    By iswan in forum AWT / Java Swing
    Replies: 0
    Last Post: September 30th, 2011, 08:03 PM
  2. Ending a method that has no return type
    By Blehs in forum Java Theory & Questions
    Replies: 3
    Last Post: August 12th, 2011, 01:56 AM
  3. error: This method must return a result of type int
    By J05HYYY in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 13th, 2011, 05:26 PM
  4. Overriding methods declaration problems
    By TurboTuring in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 9th, 2010, 11:23 AM