• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is wrong with the code MinMaxArray  RSS feed

 
Liliya Jeromin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
could anybody tell me why it delivers two Min instead of Min und Max?
Thanks


 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the Ranch.

I have to admit, I was unable to see the mistake until I fixed braces, indentation and formatting of the code.
Try do the same and see if you can see what is wrong there.

I have one question to you too. I'm very curious, how you manage to format your code that way? Do you use any IDE or plain text editor? Does your code actually looks in your environment as it looks here? Maybe copying code messes up everything?
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some good advises on code indentation you can find here and then here.
Read those posts couple of times so you understand how serious it is and to what kind of errors it may lead to ignoring to use such techniques.
 
Liliya Jeromin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:Hi, welcome to the Ranch.

I have to admit, I was unable to see the mistake until I fixed braces, indentation and formatting of the code.
Try do the same and see if you can see what is wrong there.

I have one question to you too. I'm very curious, how you manage to format your code that way? Do you use any IDE or plain text editor? Does your code actually looks in your environment as it looks here? Maybe copying code messes up everything?


Hi there,

Thank you for your answer. I'll work on my syntax and try to fix it.

As a reply for your questions: well I'm using IDE. It's very hard for me to say how I manage that, because it's hard for me to say WHAT I have managed. I'm sure for every beginner it's difficult to cope with all this syntax stuff at first. It seems to be Chinese to me.

Have a nice day
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not the syntax.
It's the presentation.  In this case the indentation of the lines.
Your IDE should have a "format code" option somewhere.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liliya Jeromin wrote:Thank you for your answer. I'll work on my syntax and try to fix it.
As a reply for your questions: well I'm using IDE. It's very hard for me to say how I manage that, because it's hard for me to say WHAT I have managed. I'm sure for every beginner it's difficult to cope with all this syntax stuff at first. It seems to be Chinese to me.

Because it's new. I'm sure if you tried to explain one of your favourite video games to me, it would be just as hard for me to understand.

Most IDE's have a "format code" button or keystroke - In Eclipse, it's Ctrl+Shift+F; not sure about others - and what it will do is correct all the alignment for you so that you can follow the logic more easily.

Try it, and I'm sure you'll work out what the problem is very quickly.

HIH

Winston
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liliya Jeromin wrote:I'm sure for every beginner it's difficult to cope with all this...
No worries, it is normal and expected

Liliya Jeromin wrote:It's very hard for me to say how I manage that, because it's hard for me to say WHAT I have managed.

Probably you'll agree, that such code looks very tricky. It is almost impossible to follow what belongs to what.
And look to this, even though code and variable names are nonsensical and has no meaning, but at least you can see the code flow structure.

Way less tricky, isn't it? This is what I meant. When you trying (actually not need to try, just need to get it right) to get formatting right, you tremendously helping yourself to avoid mistakes.

You have been given advise by others which keystrokes you could use in your IDE to format your code, so give a try. And never ever avoid braces, even if it is one statement in it. Some people do that, but maybe when they are more experienced and even then probably they wouldn't recommend that.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote:
And never ever avoid braces, even if it is one statement in it. Some people do that, but maybe when they are more experienced and even then probably they wouldn't recommend that.

No, leaving out braces even for a single-statement block is not a recommended practice. It invites bugs and you never want to do that when you are programming.
 
Liliya Jeromin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, guys, for all your responds!

I hear what you're saying and special thanks to Winston for being supportive.
I managed to format the code in Eclipse.
But I think, I don't really understand how this all is running and that is why I am not able to find the mistake.
I tried a lot of things according my logic, but it turned out to be incorrect...

I'm about to throw my laptop through the window and crash my average head against a wall
Would be thankful for any tipps...
 
Liliya Jeromin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops I meant 'hints' not 'tipps' (tips is German))
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liliya Jeromin wrote:I'm about to throw my laptop through the window and crash my average head against a wall
Would be thankful for any tipps...

OK, well now that you have it formatted, why don't you post it here (inside code tags), and explain to us where you're having problems.

Another tip(p): When you're trying to decipher code - especially loops - make sure you have lots of paper and pencils, and draw a table: perhaps something like this:Do you see the idea? It forces you to go through the logic and work out what the code should be doing, which in turn makes it easier to spot a mistake.

HIH

Winston
 
Liliya Jeromin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Didn't have time to post: everything worked the same day.

Thank you all for your help.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!