Results 1 to 8 of 8
  1. #1
    XaviannNJ is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default invalid method declaration; return type required

    What can I do to resolve this problem?:confused:

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    XaviannNJ is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    :p

    I'm quite new to java so the only return type that I know is "void" and it isn't suitable to my programm.I mean,my programm needs to return results.:p;)

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    Go thru sun tutorial.

    You paste the code till how much you tried.

    Go thru "The Complete reference" and then start coding.
    Ramya:cool:

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by XaviannNJ View Post
    :p

    I'm quite new to java so the only return type that I know is "void" and it isn't suitable to my programm.I mean,my programm needs to return results.:p;)
    Well, we're not going to be able to give you any more specific help if you don't show us the code. It's like you're asking us to help us fix your problem but refuse show us just what the problem is. :rolleyes:

  6. #6
    XaviannNJ is offline Member
    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Default

    Hehehe,you're right!So here it is!:D


    import java.io.IOException;

    public class Mathitis {
    public static main(String[] args) throws IOException {
    boolean finished = false;
    while(!finished){
    int choice=-1;
    int i;

    System.out.println("Choices are");
    System.out.println("1. Multiplication array ");
    System.out.println("2. Oddity");
    System.out.println("3. Prime number");
    System.out.println("4. GCD of i and j");
    System.out.println("0. Return to menu");

    /*Displays a menu with 5 choices
    *1.multiply i from 1 to 10 and returns the results
    *2.Check if i is odd
    *3.Check if i is a prime number
    *4.Find and print the greatest common divisor of i with j (an other number)
    *5.Returns to menu */


    System.out.print("Enter choice: ");
    choice = readPositiveInt();
    switch(choice){
    case 0:
    System.out.println("Thanks for using this programm.See you next time!Bye bye!");
    finished = true;
    break;

    case 1:
    int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10;
    i1=i*1;
    i2=i*2;
    i3=i*3;
    i4=i*4;
    i5=i*5;
    i6=i*6;
    i7=i*7;
    i8=i*8;
    i9=i*9;
    i10=i*10;

    System.out.println(i1,i2,i3,i4,i5,i6,i7,i8,i9,i10) ;
    break;
    /*Displays the multiplication array of i from 1 to 10*/

    case 2:
    if (i%2=1)
    return true;

    else
    return false;
    break; /*A number is odd when its division with 2 has 1 as remainder*/


    case 3:

    if ((i%2!=0) && (i%3!=0) && (i%5!=0) && (i%7!=0))

    return true;


    /*A prime number (or a prime) is a natural number that has exactly two distinct natural number divisors: 1 and itself.
    *So if all the former divisions are not equal to zero the number is surely prime.
    *(2,3,5 and 7 are the basic prime numbers) */




    else
    return false;
    break;

    case 4:
    int j;
    if (j==0)
    return i;
    else
    return gcd(j, i % j);



    default:
    System.out.println("Invalid choice.Try again");
    break;

    }



    }


    }







    }

    When compiled,it returns me the message that I told you!:$

  7. #7
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    Please don't copy the imcomplete code.

    Go thru tutorial.

    In the above code starting of the class itself is wrong no proper main method.

    Where is readPositiveInt method????????????
    Ramya:cool:

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 3
    Last Post: 06-05-2010, 08:05 PM
  2. invalid method declaration error
    By bsarules in forum Java Applets
    Replies: 7
    Last Post: 05-25-2010, 06:06 PM
  3. BubbleSorting Problem: invalid method declaration
    By SwEeTAcTioN in forum New To Java
    Replies: 6
    Last Post: 12-02-2009, 03:47 AM
  4. Method return type problem
    By McChill in forum New To Java
    Replies: 7
    Last Post: 05-05-2009, 09:21 PM
  5. Error: invalid method declaration
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-27-2007, 12:10 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
  •