• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please find as many syntax, style, and logic errors as there are in the code  RSS feed

 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jeremy Hutto
Greenhorn
Posts: 24
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May I ask where this code came from?
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It came from a class assignment.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

If it is an assignment, maybe you shou‍ld tell us how many errors you found. How do we know what a logic error is, until we know what the code is supposed to do?
I added code tags to your post, which makes it look a lot better () and will highlight some formatting errors. Is the formatting you have presented exactly the same as what you were given?
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
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
  • Quote
  • Report post to moderator

Why can't you simply compile it? That should take only a few seconds, and would take care of all the syntax errors.

As for the logic errors, that would require you to run (and perhaps, even add a few debugging statements), but regardless, that should take much less time than asking on a forum.

Henry
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the idea of the test was to find the errors on paper. I presume the test has been completed. What sort of mark did you get?
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already did that and marked out about five errors, but I have this nagging feeling that there's more errors in the code, thus I asked on this forum.
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the style of the entire code up to the presentable standard for someone setting out as a beginner in Java?
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I think something is wrong with the "System.out.printline ( Mystery returns " ++ mystery(list)" portion of the last line of code, but I'm not sure how to explain what's wrong.
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wasn't a test as such, but a project that was graded on an A to F scale. I got a B.
 
Jeremy Hutto
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would highly suggest watching bucky's tutorial series on youtube
We could tell you each and every error that there is, but I believe that watching someone program then programming yourself could be very helpful here.
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeremy. Could you just explain what's wrong in the last line of the code?
 
Jeremy Hutto
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That the thing, there's much more wrong with this code than just the last line.
Most of it is very basic, that's why I believe the best thing for you to do would be to actively learn by doing rather than simply asking what's wrong.
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error 1
Missing semicolon at double a = 0.0
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error 2
a ++= list{b}

I believe this should be:
a ++= list[b] since b is an array not a block of statement.
 
Phil Emn
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error 3
Missing the keyword ''new'' in the Scanner instantiation.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Emn wrote:Error 2
a ++= list{b}

I believe this should be:
a ++= list[b] since b is an array not a block of statement.
Neither of those lines will compile, even though the change from {} to [] is correct. The array is called list, not b, which appears to be an index.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One big problem with your code -- and it's not just style -- is incorrect formatting.  This will hide errors and make it very hard to anyone who is trying to work on your code later.  Check out this guide.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:One big problem with your code -- and it's not just style -- is incorrect formatting.  This will hide errors and make it very hard to anyone who is trying to work on your code later.  Check out this guide.
I did ask earlier whether the formatting was copied exactly.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Emn wrote:Is the style of the entire code up to the presentable standard for someone setting out as a beginner in Java?

As you have posted it, absolutely not. The formatting is quite atrocious but judging from the nature of the assignment, I think that was by design.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Emn wrote:Already did that and marked out about five errors, but I have this nagging feeling that there's more errors in the code, thus I asked on this forum.

Well, you're right in that. Did you not try to fix and compile the code? Almost every other line of code given has some kind of error. There are at least 2 logic errors that haven't even been discussed yet.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:. . . Almost every other line of code given has some kind of error. . . .
Only every other line? If you include stylistic errors, some people would say line 24 is correct, though I would prefer a slight change to it myself. Even I would accept line 28 26 as correct except when I have a really bad headache I would say all the other lines have some sort of error in, even if some are minor formatting errors.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!