Results 1 to 8 of 8
- 11-25-2010, 01:20 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
-
Hm, perhaps give the method a return type? :)
- 11-25-2010, 01:29 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
: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, 01:37 PM #4
Go thru sun tutorial.
You paste the code till how much you tried.
Go thru "The Complete reference" and then start coding.Ramya:cool:
-
- 11-25-2010, 01:44 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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, 01:49 PM #7
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:
-
Agree with the above. You need to give main a void return type but do not do this.
Similar Threads
-
Error: invalid method declaration; return type required
By silvia in forum AWT / SwingReplies: 3Last Post: 06-05-2010, 08:05 PM -
invalid method declaration error
By bsarules in forum Java AppletsReplies: 7Last Post: 05-25-2010, 06:06 PM -
BubbleSorting Problem: invalid method declaration
By SwEeTAcTioN in forum New To JavaReplies: 6Last Post: 12-02-2009, 03:47 AM -
Method return type problem
By McChill in forum New To JavaReplies: 7Last Post: 05-05-2009, 09:21 PM -
Error: invalid method declaration
By silvia in forum New To JavaReplies: 1Last Post: 07-27-2007, 12:10 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks