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

Printable View

- 11-25-2010, 02:20 PMXaviannNJinvalid method declaration; return type required
What can I do to resolve this problem?:confused:

- 11-25-2010, 02:26 PMFubarable
Hm, perhaps give the method a return type? :)

- 11-25-2010, 02:29 PMXaviannNJ
: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;) - 11-25-2010, 02:37 PMRamyaSivakanth
Go thru sun tutorial.

You paste the code till how much you tried.

Go thru "The Complete reference" and then start coding. - 11-25-2010, 02:41 PMFubarable
- 11-25-2010, 02:44 PMXaviannNJ
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!:$ - 11-25-2010, 02:49 PMRamyaSivakanth
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???????????? - 11-25-2010, 02:59 PMFubarable
Agree with the above. You need to give main a void return type but do not do this.