Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

methods within methods?

 
Ranch Hand
Posts: 274
  • 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

 
author
Posts: 23879
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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: 274
  • Mark post as helpful
  • send pies
  • Report post to moderator
That was it, thanks!
 
kennith stomps
Ranch Hand
Posts: 274
  • 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: 274
  • 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: 274
  • Mark post as helpful
  • send pies
  • Report post to moderator
Errors all over the place
 
Bartender
Posts: 7208
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java 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: 274
  • 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
Bartender
Posts: 7208
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
 
Master Rancher
Posts: 3883
35
  • 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.
 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • 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
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic