• Post Reply Bookmark Topic Watch Topic
  • New Topic

For Loop Help  RSS feed

 
John Belceto
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to produce this ouput using a for loop:
Five spaces)1
Four spaces)2
Three Spaces) 3
Two Spaces)4
One Space)5
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

What have you tried and what are you having trouble with? Do you know how a for-loop works? Can you identify a pattern in the desired output?
 
John Belceto
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know for loops work and I keep getting logic errors. I can print the numbers with for loops but just can't seem to get the spaces and the numbers.
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us what you tried.
 
Junilu Lacar
Sheriff
Posts: 11493
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about this for a pattern?

5 + 1 = 6
4 + 2 = 6
3 + 3 = 6
2 + 4 = 6
1 + 5 = 6
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!