• Post Reply Bookmark Topic Watch Topic
  • New Topic

For-loop & array & randomNumbers  RSS feed

 
Patrik sjostrand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody!

I have a problem with my output from an for-loop, here is some of my code:



(Random numbers)

The answer now is:

These are the numbers between 500 - 999: 560
These are the numbers between 500 - 999: 600
These are the numbers between 500 - 999: 700

I want :

These are the numbers between 500 - 999:
560 600 700

Sorry for my english

Regards

/Patrik
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You didn’t say what you wanted your code to do, so we can’t tell what is going wrong.
 
Patrik sjostrand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey again!

Thanks.. :-)


I want my code to write this output:




These numbers are between 500 - 999:

600 700 987 934 234 567 345 ...

instead for


These numbers are between 500 - 999: 600
These numbers are between 500 - 999: 700
These numbers are between 500 - 999: 987
These numbers are between 500 - 999: 934
These numbers are between 500 - 999: 234
...

So i think that my system.out.println("These are the..." + v3[i]); line should not be in the for-loop but i don´t remember how to do it??



Regards
/P





 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want my code to write this output: .....
Please paste the full code. Would like to have a look at that. I presume you are attempting to print the numbers between 500 and 999. Correct?
 
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
Patrik sjostrand wrote:
I want my code to write this output:

These numbers are between 500 - 999:

600 700 987 934 234 567 345 ...


instead for

These numbers are between 500 - 999: 600
These numbers are between 500 - 999: 700
These numbers are between 500 - 999: 987
These numbers are between 500 - 999: 934
These numbers are between 500 - 999: 234
...

So i think that my system.out.println("These are the..." + v3[i]); line should not be in the for-loop but i don´t remember how to do it??



What do you mean you don't remember how to do it? You don't know how to move code around in general? Or is this related to some sort of pattern you are thinking of?

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!