Bookmark Topic Watch Topic
  • New Topic

methods within methods?  RSS feed

 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Report post to moderator
Any ideas on what I may be doing wrong?

Error

Multiple markers at this line
- Syntax error on token(s), misplaced
construct(s)
- Syntax error, insert ";" to complete
BlockStatements

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Java does not allow methods to be declared directly in the body of another method.

Henry
 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Report post to moderator
That was it, thanks!
 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Report post to moderator
How would you go about sending the user input of the getMenuOption to another method?
 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Report post to moderator


I have been reading up on it and this is the best I could come up with. I am confused as to how to call the method, and which brackets go where

 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Report post to moderator
Errors all over the place
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
A method must declare the types for each parameter, e.g. getMenuOption( int i ).
Except, I don't see the purpose of your method taking any arguments at all.
 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Report post to moderator
Here is one attempt at it, I keep getting the error of duplicat variable int n1, while that seems to be the correct way to code a method
 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Report post to moderator
the error of duplicat variable int n1,

The compiler sees two definitions for n1:
line 15   public static int getMenuOption(int n1) {
line 27      int n1 = input.nextInt();

A variable can only be define one time in any scope.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
The OP created a new topic and I was unable to merge them, so let's continue the discussion over on the new topic:

https://coderanch.com/t/685003/java/Methods#3215008
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!