Results 1 to 9 of 9
- 05-25-2011, 05:07 PM #1
Member
- Join Date
- May 2011
- Posts
- 8
- Rep Power
- 0
Issue with "void type not allowed here" and I cannot see why.
So I started my first Java class last week, and Ia m having problems. The question I have in my assignment is;
"Create an application named TestMethods whose main() methods holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayIt(), displayItTimesTwo(), and displatItPlusOneHundred(). Create each method to perform the task its name implies. Save the application as TestMethods.java."
So this is what I have so far...
Java Code:public class TestMethods { public static void main(String[] args) { int myVariable1 = 10; int myVariable2 = 27; System.out.println(displayIt (myVariable1, myVariable2)); } public static void displayIt(int myVariable1, int myVariable2) { System.out.println("My two variables are " + myVariable1 + " and " + myVariable2); } }
I keep getting "void type not allowed here" on line 16 which is bold. What am I doing wrong here? This is my first assignment, and it has been frustrating. I know it's an easy question, but I cannot get it in to code for the very first part. Any help is greatly appreciated.Last edited by DarrylBurke; 05-25-2011 at 05:38 PM. Reason: Added code tags, removed blank lines in code
- 05-25-2011, 05:39 PM #2
See answer on the other forum where you posted this question.
1st Java class assignment, and having some difficulties. Little help please.Last edited by Norm; 05-25-2011 at 05:44 PM.
- 05-25-2011, 05:40 PM #3
You're asking System.out to println the value returned by displayIt(...). Problem is, that method doesn't return a value.
db
- 05-25-2011, 05:44 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
Also I think this:
"In turn, pass each value to methods named displayIt(), displayItTimesTwo(), and displatItPlusOneHundred()."
means that the methods take one integer and does what the method says with it. You then call this method once for the first integer then again for the second one.
It doesn't imply to me that you send in both integers at the same time, otherwise they'd be called displayThem...etc.
- 05-25-2011, 05:52 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 05-25-2011, 05:58 PM #6
Not everyone lives in Holland.
- 05-25-2011, 06:03 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,479
- Rep Power
- 16
Which is probably a good thing as it would get a little crowded...
Imagine the property prices!
- 05-25-2011, 06:14 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 05-25-2011, 06:26 PM #9
Similar Threads
-
void type not allowed
By jockhip12 in forum New To JavaReplies: 6Last Post: 05-05-2011, 05:26 PM -
Equivalent of " void* " in JAVA
By ABHIJEEEEEEET in forum New To JavaReplies: 7Last Post: 08-16-2010, 06:55 AM -
How can I solve "void cannot be dereferenced" error?
By fervent07 in forum New To JavaReplies: 2Last Post: 04-05-2010, 08:54 PM -
How can I prevent "found void but expected java.lang.String" ?
By trueblue in forum New To JavaReplies: 3Last Post: 05-21-2009, 03:48 PM -
'void' type not allowed here
By Torgero in forum New To JavaReplies: 15Last Post: 10-04-2008, 11:08 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks