• Post Reply Bookmark Topic Watch Topic
  • New Topic

identifier expected  RSS feed

 
Steph Millar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I'm new to Java and on this code i'm getting the error:

<identifier> expected

on line 25.

This code is supposed to allow for the 10 marks to be entered and then the results to be printed out.
Can someone please tell me where i'm going wrong?


Thanks in advance!
Stephanie



 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method signature on line 25 is incomplete. You have named the parameter but not indicated its type.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the method declaration of: printgrades, you are missing the data type for the marks parameter.
 
Steph Millar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please show me what they mean by their reply?

 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steph Millar wrote:Could someone please show me what they mean by their reply?


Have a look at how the main method is declared. See the way the args variable is assigned a type (String []). Also look at other variables being used- all of them have types associated with them.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steph Millar wrote:Could someone please show me what they mean by their reply?






You haven't indicated the type of "marks". Every time you declare a variable, you have to indicate its type.



where "???" gets replaced by int or String or LeftHandedWombat or whatever type "marks" is supposed to be.

 
Steph Millar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've changed line 25 to:




and am now getting an error of:

.class expected

on this line




Why is this?
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have formatted the code which you posted in your first post. See if you can really compile the code you have posted.

The marks in your case is an array of int. So the method printgrades also expects the marks to be an array of int.
Just calling the System.out.println on the instance would invoke the toString of that class. So in your case you would be better off iterating through the array and then printing the values.

Also you have named your class as marks, then there are variables which are named as marks and this leads to a lot of confusion as to whether marks is a type (because of its class name) or is it a variable name (because its declared as int marks[]).

So use a proper naming convention and also carefully understand the compiler errors as they give you lot of information and help you in identifying the issue.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually that's due to having an error somewhere else...your braces don't match or some such. Without seeing ALL your code, we can't really say specifically where the problem is.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some other comments:

By conventaion, class names are capitalized: class marks should be Marks.

Line 6, getinputmarks() (by convention should be getInputMarks()) is to return an int, but you return marks, which is an array of ints.

Avoid using hardcoded values as loop limits. Line 11, for (int i = 0; i < 10; i++), would be better as for (int i = 0; i < marks.length; i++). Remember, length is an array property, not a method, so doesn't have ()s.

Line 25, printgrades() (by convention should be printGrades()), you have a similar return problem as with getinputmarks(), but you should also be getting an error says that you must return an int. The compiler assumes that return statements in if statements may not execute.

Keep coding.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've got several problems in your code, and you seem to be at a loss as to how to even begin attacking them. (Not necessarily a bad thing--quite common for a beginner.) In order to make your life easier, I suggest you take things in much smaller steps.

Start with just an empty main method. Compile it.

Add a tiny method to do nothing more than read an int from input and print it out. Compile it. Test it.

Add a tiny method that creates a small array (say, 3 elements), populates it, and prints out each element. Without using the "read input" method--just hardcode everything. Compile it. Test it.

Then change from hardcoded values for your array to use 3 ints that the user inputs. Compile it. Test it.

And so on.

I'm sure it may seem like that will just take forever and it's too much work for such small steps, but I promise you, it will be worth it. When you encounter a problem, either in compiling or testing, you'll know exactly where it must have come from, since you only changed a tiny bit. Even with the rather modest piece of code you've got so far, you're floundering. The best way to get less lost is to take smaller bites.

 
Chetan Sarnad
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not pretty sure about your requirement. Just refer the rectified version of your code to read the marks into an array of integers and to display the marks along with the fail and pass comments based on the marks.

[Code Removed]
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chetan Sarnad wrote:I am not pretty sure about your requirement. Just refer the rectified version of your code


Please don't do that. This site is NotACodeMill. If you do the OP's work for her, she won't learn. And, as it clearly states at the top of the topics list page (and as I would have hoped would be common sense): "We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers."

 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chetan Sarnad wrote:I am not pretty sure about your requirement. Just refer the rectified version of your code to read the marks into an array of integers and to display the marks along with the fail and pass comments based on the marks.


As mentioned by Jeff in his previous reply, we should avoid providing complete solutions to the queries as this will not help them in learning. Hence I have removed the code which you had posted. You are always welcome to provide hints, provide suggestions for code improvement or any other useful information which will help OP to solve the question.
 
Chetan Sarnad
Greenhorn
Posts: 22
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry friends, wont repeat it. I do agree that we are all here to learn and explore Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!