• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why is this code not returning anything?  RSS feed

 
Estelle Sousou
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm beginner in Java and would appreciate your help.

The following code runs fine but returns nothing:


Any idea what's the problem?

Thanks a lot!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I edited your post to use code tags. It's much easier to read now.

Try adding this line just before your for loop:

System.out.println(populationCourante + ", " + populationCible);

It will print

7.0, 8.5

since your for loop says "populationCourante >= populationCible", this is false, so you never enter the loop, so nothing prints.
 
Estelle Sousou
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

Stupid mistake from me!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guarantee you that everyone here either a) has done that, b) will do it , or c) lies and says they've never done it.

It's how we learn.

Remember that System.out.println() can be your best friend. When your program does something you KNOW is impossible, print out stuff to find out what it is thinking vs. what YOU are thinking.
 
Estelle Sousou
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Fred!

I'm currently stuck in this code and would appreciate your help




What I need to do is to divide tauxCroissance/2 anytime populationCourante is double, triple ... of populationInitiale.

My code above only divide tauxCroissance by 2 once , and I was thinking of instead of using if (populationCourante >= (populationInitiale*2) I could use f (populationCourante % populationInitiale = 0).

Any help?

Thanks
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Estelle Sousou wrote:What I need to do is to divide tauxCroissance/2 anytime populationCourante is double, triple ... of populationInitiale.

I admit I have a hard time reading your code, because "tauxCroissance" means nothing to me. I only know English...and some would say not very well at that.

are populationCourante and tauxCroissance integer types? if so, then yes, I think using the mod operator would work. Be careful with your use of "=" vs "==". They do VERY different things.

Also, if you use the mod operator like that, you may need to make sure populationCourante and tauxCroissance are not equal. If they are both (say) 20, the the mod operator will return 0, which I don't think you want...but again I'm not sure.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!