java question

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 1175 Views - Last Post: 19 October 2013 - 10:32 PM Rate Topic: -----

#16 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3620
  • View blog
  • Posts: 12,497
  • Joined: 12-December 12

Re: java question

Posted 06 October 2013 - 10:12 AM

@OP You still aren't using CODE tags consistently and there is no need to keep quoting (or attempting to quote) the previous post.

When you are typing your post it tells you how to use code tags directly in the area where you are typing. Press the Preview Post button until it is correct.

This post has been edited by andrewsw: 06 October 2013 - 10:13 AM

Was This Post Helpful? 0
  • +
  • -

#17 manofax  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 20
  • Joined: 17-May 13

Re: java question

Posted 06 October 2013 - 10:42 AM

Is there a reason you have a while() loop in your code, seemingly doing nothing? :D What i meant about the bracers was this:

if(age<30 && age>=20){

//do stuff

}else if(age<40 && age>=30){

//do stuff

}else if(age<20 && age>0){

//do stuff

}


By doing it the way you are doing it makes it difficult to understand what each if statement is handling. It could also cause one of your if statements to become 'nested' in another, meaning that it will never be used for comparison (because if it gets in there in the first place, the comparison criteria won't match the second 'if' anyway).

The bracers are there so that you can encapsulate the functionality you wish to execute, or if you are struggling to understand that, they are there to ensure that the result of the code inside the for loop is executed in isolation. Make sure that your if statement handles ONLY what you want it to handle, this can be done by using bracers, and breaking your if statements up correctly as I've shown you above...

The rest of your code is fine (besides the random while loop), but remember that you also want to record each category when it enters the if statement that it is relevant to! (hint: increment the category integer by 1 every time it enters the if statement it belongs to!)

Then you can use your category values outside your for loop, and display how many members are inside each category!

That's about all i can offer you without giving you the solution myself (which I have been on the brink of doing a few times), so best of luck with finishing your assignment! I hope I've been able to help you with the questions you had!
Was This Post Helpful? 0
  • +
  • -

#18 dark_chocolate  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 06-October 13

Re: java question

Posted 06 October 2013 - 10:42 AM

:dontgetit:

View Postandrewsw, on 06 October 2013 - 10:12 AM, said:

@OP You still aren't using CODE tags consistently and there is no need to keep quoting (or attempting to quote) the previous post.

When you are typing your post it tells you how to use code tags directly in the area where you are typing. Press the Preview Post button until it is correct.

Was This Post Helpful? 0
  • +
  • -

#19 dark_chocolate  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 06-October 13

Re: java question

Posted 06 October 2013 - 10:48 AM

Thank you so much for help :rolleyes:/
I will try my best even if get a wrong answer >.<

This post has been edited by andrewsw: 06 October 2013 - 10:57 AM

Was This Post Helpful? 0
  • +
  • -

#20 manofax  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 20
  • Joined: 17-May 13

Re: java question

Posted 06 October 2013 - 10:54 AM

Remember, "You never fail until you stop trying" ~ Albert Einstein :D

Good luck, and keep learning!
Was This Post Helpful? 0
  • +
  • -

#21 Javanaut  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-October 13

Re: java question

Posted 19 October 2013 - 10:32 PM

You are also looping for the length of age which makes no sense, you should be using the number variable as the length of your for loop.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2